• 图片压缩质量并保存指定尺寸


    /// <summary>
    /// 按比例缩小图片,自动计算高度
    /// </summary>
    /// <param name="stroldpic">源图文件名(包括路径)</param>
    /// <param name="strnewpic">缩小后保存为文件名(包括路径)</param>
    /// <param name="intwidth">缩小至宽度</param>
    public string smallpic(string stroldpic, string strnewpic, int intwidth)
    {
    System.Drawing.Bitmap objpic, objnewpic;
    try
    {
    objpic = new System.Drawing.Bitmap(stroldpic);
    string path = "";
    if (objpic.Width > 500)
    {
    double intheight = (Convert.ToDouble(intwidth) / Convert.ToDouble(objpic.Width)) * Convert.ToDouble(objpic.Height);
    objnewpic = new System.Drawing.Bitmap(objpic, intwidth, Convert.ToInt32(intheight));
    System.Drawing.Imaging.EncoderParameter p;
    System.Drawing.Imaging.EncoderParameters ps;

    ps = new System.Drawing.Imaging.EncoderParameters(1);

    p = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);
    ps.Param[0] = p;
    objnewpic.Save(strnewpic,GetCodecInfo("image/jpeg"), ps);
    path = "1";
    }
    return path;
    }
    catch (Exception exp) { throw exp; }
    finally
    {
    objpic = null;
    objnewpic = null;
    }
    }

    private static System.Drawing.Imaging.ImageCodecInfo GetCodecInfo(string mimeType)
    {
    System.Drawing.Imaging.ImageCodecInfo[] CodecInfo = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
    foreach (System.Drawing.Imaging.ImageCodecInfo ici in CodecInfo)
    {
    if (ici.MimeType == mimeType) return ici;
    }
    return null;
    }

  • 相关阅读:
    Ubuntu下SSH设置
    Runtime.getRuntime().exec学习记录[转贴]
    ffmpeg参数说明(转载)
    学习NSNotification经历
    iphone 推送服务Apple Push Notification Service
    MFC枚举窗口
    WebQQ协议分析(3)——获取用户信息
    Cannot access a disposed object
    WebQQ协议分析(1)——登录
    WebQQ协议分析(4)——获取好友信息(1)
  • 原文地址:https://www.cnblogs.com/codeloves/p/3092254.html
Copyright © 2020-2023  润新知