zoukankan      html  css  js  c++  java
  • C# 压缩图片 HttpPostedFile转Image

                    #region 以下代码为保存图片时,设置压缩质量
                        Image iSource = Image.FromStream(file.InputStream);//HttpPostedFile转Image
                 long[] qy = new long[1];
      qy[0] = 10;//设置压缩的比例1-100 ImageFormat tFormat
    = iSource.RawFormat; int sW = iSource.Width, sH = iSource.Height; Tool tool = new Tool(); tool.GetPicZoomSize(ref sW, ref sH, 640, 360); Bitmap filemap = new Bitmap(640, 360); Graphics g = Graphics.FromImage(filemap); g.Clear(Color.WhiteSmoke); g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(iSource, new Rectangle((640 - sW) / 2, (360 - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel); g.Dispose(); //Bitmap filemap = (Bitmap)Image.FromStream(file.InputStream);//HttpPostedFile转Bitmap EncoderParameters ep = new EncoderParameters(); EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy); ep.Param[0] = eParam; ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegICIinfo = null; for (int x = 0; x < arrayICI.Length; x++) { if (arrayICI[x].FormatDescription.Equals("JPEG")) { jpegICIinfo = arrayICI[x]; break; } } filemap.Save(FilePath + FileName + fileExt, jpegICIinfo, ep);//dFile是压缩后的新路径 filemap.Dispose(); #endregion
  • 相关阅读:
    Photon3Unity3D.dll 解析三——OperationRequest、OperationResponse
    关于VS2010的一些操作
    Photon3Unity3D.dll 解析二——EventData
    Photon3Unity3D.dll 解析一
    关于U3D中的移动和旋转
    U3D的一些常用基础脚本
    U3D模拟仿真实现
    构建基于TCP的应用层通信模型
    TCP协议的三次握手
    Python生成随机字符串
  • 原文地址:https://www.cnblogs.com/94LH-shuai/p/10683982.html
Copyright © 2011-2022 走看看