文件名称:VS2010做的C#图片缩放实例
文件大小:85KB
文件格式:RAR
更新时间:2020-10-04 09:50:08
VS2010 图片缩放
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();
【文件预览】:
Image_Scale_Demo
----Image_Scale_Demo.suo(20KB)
----Image_Scale_Demo()
--------Program.cs(498B)
--------Image_Scale_Demo.csproj(5KB)
--------w_main.cs(4KB)
--------w_main.Designer.cs(4KB)
--------Properties()
--------EnglishChar.bmp(245KB)
--------Image_Scale_Demo_TemporaryKey.pfx(2KB)
--------ChineseChar.bmp(595KB)
--------Image_Scale_Demo.csproj.user(452B)
--------obj()
--------w_main.resx(6KB)
--------bin()
----Image_Scale_Demo.sln(890B)