Microsoft Visual Studio 2010做的C#图片缩放实例,主要代码: Image imageSource = bitmapSource; ImageFormat sourceFormat = imageSource.RawFormat; int iSourceWidth = imageSource.Width; int iSourceHeight = imageSource.Height; decimal decTargetWidth = iSourceWidth*decTimes; decTargetWidth = Math.Round(decTargetWidth, 0); string sTargetWidth = decTargetWidth.ToString( ); int iTargetWidth = Int32.Parse(sTargetWidth); decimal decTargetHeight = iSourceHeight * decTimes; decTargetHeight = Math.Round(decTargetHeight, 0); string sTargetHeight = decTargetHeight.ToString(); int iTargetHeight = Int32.Parse(sTargetHeight); Bitmap bitmapTarget = new Bitmap(iTargetWidth, iTargetHeight); Graphics gTarget = Graphics.FromImage(bitmapTarget); gTarget.Clear(Color.Transparent); // 设置画布的描绘质量 gTarget.CompositingQuality = CompositingQuality.HighQuality; gTarget.SmoothingMode = SmoothingMode.HighQuality; gTarget.InterpolationMode = InterpolationMode.HighQualityBicubic; gTarget.DrawImage(imageSource, new Rectangle(0, 0, iTargetWidth, iTargetHeight), 0, 0, imageSource.Width, imageSource.Height, GraphicsUnit.Pixel); gTarget.Dispose(); // 以下代码为保存图片时,设置压缩质量 EncoderParameters encoderParams = new EncoderParameters(); long[] lQualityS = new long[1]; lQualityS[0] = 100; EncoderParameter EncoderParameterVar = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lQualityS); encoderParams.Param[0] = EncoderParameterVar; imageSource.Dispose();
- 1
- 粉丝: 40
- 资源: 131
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助