zoukankan      html  css  js  c++  java
  • 生成缩略图

    public bool GetReducedImage(string srouceImage, int smallHeight, ref string retInfo)
    {
    Image ReducedImage = null;
    Image ResourceImage=null;
    retInfo = "";
    try
    {
    string smallfilename = Path.GetFileNameWithoutExtension(srouceImage) + "_small" + Path.GetExtension(srouceImage);

    string targetFilePath = Path.GetDirectoryName(srouceImage) + Path.DirectorySeparatorChar + smallfilename;

    if (File.Exists(targetFilePath))
    {
    File.Delete(targetFilePath);
    }

    ResourceImage = Image.FromFile(srouceImage);

    int ImageHeight = smallHeight;

    int ImageWidth = Convert.ToInt32((float)smallHeight / ResourceImage.Height * ResourceImage.Width);

    Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);

    ReducedImage = ResourceImage.GetThumbnailImage(ImageWidth, ImageHeight, callb, IntPtr.Zero);

    ReducedImage.Save(@targetFilePath, ImageFormat.Jpeg);

    return true;
    }
    catch (Exception ex)
    {
    retInfo = ex.Message;
    return false;
    }
    finally
    {
    if (ReducedImage != null)
    {
    ReducedImage.Dispose();
    }
    if (ResourceImage != null)
    {
    ResourceImage.Dispose();
    }
    }
    }

    public bool ThumbnailCallback()
    {
    return false;
    }

  • 相关阅读:
    Spark介绍与环境搭建
    Kafka基本操作
    Hadoop的HDFS概述
    hadoop环境搭建
    常用小工具
    mac机
    Eclipse使用
    微信公众号开发
    PM2
    JS 零散知识点
  • 原文地址:https://www.cnblogs.com/flish/p/6579808.html
Copyright © 2011-2022 走看看