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;
    }

  • 相关阅读:
    skill:极角排序
    skill:树的重心
    [CF1091F](New Year and the Mallard Expedition)
    2018九省联考(SHOI2018)
    陷入僵局?
    2333
    雨后天晴
    听说我首次抢到食堂最早的馄饨
    难题做不动
    成绩出来了?
  • 原文地址:https://www.cnblogs.com/flish/p/6579808.html
Copyright © 2011-2022 走看看