• .net生成图片缩略图


    实现方法有2个方式:

     1. 使用Image的GetThumbnailImage 方法直接生成压缩图片,大概大概如此:

       file://设置 原图片 对象的 EncoderParameters 对象,设置清晰度
       ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);
       EncoderParameters parameters = new EncoderParameters(1);
       parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);

       System.Drawing.Image.GetThumbnailImageAbort myCallback =new

       System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
       System.Drawing.Image myThumbnail = image.GetThumbnailImage(intNewWidth, intNewHeight,

     myCallback, IntPtr.Zero);
      myThumbnail.Save(txtNewPath, ici, parameters);

     2. 使用Graphics 重新绘制图象

       ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);
       EncoderParameters parameters = new EncoderParameters(1);
       parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);

       Bitmap objNewBitMap = new Bitmap(intNewWidth, intNewHeight, PixelFormat.Format32bppArgb);
       //从指定的 Image 对象创建新 Graphics 对象
       Graphics objGraphics = Graphics.FromImage(objNewBitMap);
       //清除整个绘图面并以透明背景色填充
       objGraphics.Clear(Color.Transparent);
       //在指定位置并且按指定大小绘制 原图片 对象
       objGraphics.DrawImage(image, new Rectangle(0, 0, intNewWidth, intNewHeight));
       objNewBitMap.Save(txtNewPath + txtNewFileName+"."+mFileExtName, ici, parameters);

      注意lngDefinition是调整清晰度的LONG型参数,一般50-90 就很清晰了。

      2种效果,(相同宽度高度)清晰度上Graphics较好,图片Graphics绘制的也比较小,小1/3左右。
  • 相关阅读:
    Flask学习笔记(10):钩子函数
    Flask学习笔记(8):csrf攻防
    Flask学习笔记(7):flask-migrate
    Flask学习笔记(6):flask-script
    Flask学习笔记(5):session
    Flask学习笔记(4):cookie
    Flask学习笔记(3):上传文件
    WTForm表单验证
    WINDOWS CMD命令小集
    Alembic环境配置与基本操作
  • 原文地址:https://www.cnblogs.com/SingleCat/p/1581624.html
Copyright © 2020-2023  润新知