当前位置: 首页>>代码示例>>C#>>正文


C# EncoderParameters.Dispose方法代码示例

本文整理汇总了C#中System.Drawing.Imaging.EncoderParameters.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# EncoderParameters.Dispose方法的具体用法?C# EncoderParameters.Dispose怎么用?C# EncoderParameters.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Imaging.EncoderParameters的用法示例。


在下文中一共展示了EncoderParameters.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateHighThumbnail

        /// <summary>
        /// 使用方法调用GenerateHighThumbnail()方法即可
        /// 参数oldImagePath表示要被缩放的图片路径
        /// 参数newImagePath表示缩放后保存的图片路径
        /// 参数width和height分别是缩放范围宽和高
        /// </summary>
        /// <param name="oldImagePath"></param>
        /// <param name="newImagePath"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public static void GenerateHighThumbnail(string oldImagePath, string newImagePath, int width, int height)
        {
            System.Drawing.Image oldImage = System.Drawing.Image.FromFile(oldImagePath);
            int newWidth = AdjustSize(width, height, oldImage.Width, oldImage.Height).Width;
            int newHeight = AdjustSize(width, height, oldImage.Width, oldImage.Height).Height;

            System.Drawing.Image thumbnailImage = oldImage.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(thumbnailImage);
            //处理JPG质量的函数
            System.Drawing.Imaging.ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
            if (ici != null)
            {
                System.Drawing.Imaging.EncoderParameters ep = new System.Drawing.Imaging.EncoderParameters(1);
                ep.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100);
                bm.Save(newImagePath, ici, ep);
                //释放所有资源,不释放,可能会出错误。
                ep.Dispose();
                ep = null;
            }
            ici = null;
            bm.Dispose();
            bm = null;
            thumbnailImage.Dispose();
            thumbnailImage = null;
            oldImage.Dispose();
            oldImage = null;
        }
开发者ID:AAlben,项目名称:Mall_WeChart_Nf,代码行数:37,代码来源:ImageOpeHelper.cs

示例2: Zoom

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sourceImage"></param>
        /// <param name="fileSavePath"></param>
        /// <param name="quality"></param>
        /// <param name="imageFormat"></param>
        public static void Zoom(Image sourceImage, string fileSavePath , int quality , string imageFormat)
        {
            //创建目录
            string dir = Path.GetDirectoryName(fileSavePath);
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            //缩略图对象
            Image resultImage = new Bitmap(sourceImage.Width , sourceImage.Height );
            Graphics resultG = Graphics.FromImage(resultImage);
            //设置质量
            resultG.InterpolationMode = InterpolationMode.HighQualityBicubic;
            resultG.SmoothingMode = SmoothingMode.HighQuality;
            //用指定背景色清空画布
            resultG.Clear(Color.White);
            //绘制缩略图

            Rectangle sRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
            Rectangle dRect = sRect;

            resultG.DrawImage( sourceImage , dRect, sRect, System.Drawing.GraphicsUnit.Pixel);

            //关键质量控制
            //获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
            ImageCodecInfo[] icis = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo i in icis)
            {
                //if (i.MimeType == "image/jpeg" || i.MimeType == "image/bmp" || i.MimeType == "image/png" || i.MimeType == "image/gif")
                if( i.MimeType == imageFormat )
                {
                    ici = i;
                }
            }
            EncoderParameters ep = new EncoderParameters(1);
            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);

            //保存缩略图
            resultImage.Save(fileSavePath , ici, ep);

            //释放关键质量控制所用资源
            ep.Dispose();

            //释放缩略图资源
            resultG.Dispose();
            resultImage.Dispose();

            //释放原始图片资源
            //initImage.Dispose();
        }
开发者ID:jxdong1013,项目名称:archivems,代码行数:57,代码来源:ImageZoomByQuality.cs

示例3: SaveJpeg

        /// <summary> 
        /// Saves an image as a jpeg image, with the given quality 
        /// </summary> 
        public static void SaveJpeg(this Bitmap image, string path, int quality)
        {
            if ((quality < 0) || (quality > 100))
            {
                string error = string.Format("Jpeg image quality must be between 0 and 100, with 100 being the highest quality.  A value of {0} was specified.", quality);
                throw new ArgumentOutOfRangeException(error);
            }

            var qualityParam = new EncoderParameter(Encoder.Quality, quality);
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");

            var encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
            image.Save(path, jpegCodec, encoderParams);
            encoderParams.Dispose();
        }
开发者ID:teleportator,项目名称:sharpcms,代码行数:19,代码来源:BitmapExtentions.cs

示例4: CreateThumbnail

 public static void CreateThumbnail(string sourceFilename, string destFilename, int width, int height)
 {
     Image image = Image.FromFile(sourceFilename);
     if ((image.Width <= width) && (image.Height <= height))
     {
         File.Copy(sourceFilename, destFilename, true);
         image.Dispose();
     }
     else
     {
         int num = image.Width;
         int num2 = image.Height;
         float num3 = ((float)height) / ((float)num2);
         if ((((float)width) / ((float)num)) < num3)
         {
             num3 = ((float)width) / ((float)num);
         }
         width = (int)(num * num3);
         height = (int)(num2 * num3);
         Image image2 = new Bitmap(width, height);
         Graphics graphics = Graphics.FromImage(image2);
         graphics.Clear(Color.White);
         graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
         graphics.SmoothingMode = SmoothingMode.HighQuality;
         graphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(0, 0, num, num2), GraphicsUnit.Pixel);
         EncoderParameters encoderParams = new EncoderParameters();
         EncoderParameter parameter = new EncoderParameter(Encoder.Quality, 100L);
         encoderParams.Param[0] = parameter;
         ImageCodecInfo[] imageEncoders = ImageCodecInfo.GetImageEncoders();
         ImageCodecInfo encoder = null;
         for (int i = 0; i < imageEncoders.Length; i++)
         {
             if (imageEncoders[i].FormatDescription.Equals("JPEG"))
             {
                 encoder = imageEncoders[i];
                 break;
             }
         }
         image2.Save(destFilename, encoder, encoderParams);
         encoderParams.Dispose();
         parameter.Dispose();
         image.Dispose();
         image2.Dispose();
         graphics.Dispose();
     }
 }
开发者ID:davinx,项目名称:himedi,代码行数:46,代码来源:ResourcesHelper.cs

示例5: Execute

        public void Execute(CommandContext context)
        {
            Bitmap bitmap = null;
            EncoderParameters encoderParams = null;
            EncoderParameter parameter = null;
            try
            {
                var temp = Environment.GetEnvironmentVariable("TEMP");
                var picPath = temp + "\\" + Guid.NewGuid() + ".bmp";

                var webcam = new WebCamUtility(context.Handle, 600, 480);
                webcam.StartWebCam();
                webcam.GrabImage(context.Handle, picPath);
                webcam.CloseWebcam();

                bitmap = new Bitmap(picPath);
                var codecInfo = GetCodecInfo("image/jpeg");
                var quality = Encoder.Quality;
                encoderParams = new EncoderParameters(1);
                const long num = 0x5fL;
                parameter = new EncoderParameter(quality, num);
                encoderParams.Param[0] = parameter;

                var newPicPath = picPath.Replace("bmp", "jpg");
                bitmap.Save(newPicPath, codecInfo, encoderParams);

                if (context.SendPhotoByEmail)
                {
                    SendComment(context, "#PCң����#���ڷ������WebCamץ�ĵ����ָ��Email�У����һ��ȥ���ա�");
                    SendPhotoByEmail(context, newPicPath);
                }
                else
                {
                    SendComment(context, "#PCң����#�����ϴ����WebCamץ�ģ�һ�Ὣ��������������΢���С�");
                    context.WeiboService.SendWeiboWithPicture("������ʹ��#PCң����#�����ҵ�WebCamץ�� " + DateTime.Now.ToLongTimeString(), newPicPath);
                }

            }
            finally
            {
                if (parameter != null) parameter.Dispose();
                if (encoderParams != null) encoderParams.Dispose();
                if (bitmap != null) bitmap.Dispose();
            }
        }
开发者ID:terryso,项目名称:PCRemote,代码行数:45,代码来源:PhotoCommand.cs

示例6: ConvertPngToJpeg

        public static void ConvertPngToJpeg(string sourceFilePath, string destinationFilePath)
        {
            try
            {
                ImageCodecInfo[] ImageCodecs = new ImageCodecInfo[0];
                EncoderParameters Encoder;
                Bitmap Bmpmages = new Bitmap(sourceFilePath);
                ImageCodecs = ImageCodecInfo.GetImageEncoders();
                Encoder = new EncoderParameters(1);

                Encoder.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100);

                Bmpmages.Save(destinationFilePath);

                Bmpmages.Dispose();
                Encoder.Dispose();
            }
            catch (Exception)
            {
            }
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:21,代码来源:DIVideoSource.cs

示例7: GetEncodingParameters

        /// <summary>
        /// Returns an instance of EncodingParameters for jpeg compression. 
        /// </summary>
        /// <param name="quality">The quality to return the image at.</param>
        /// <returns>The encodingParameters for jpeg compression. </returns>
        public static EncoderParameters GetEncodingParameters(int quality)
        {
            EncoderParameters encoderParameters = null;
            try
            {
                // Create a series of encoder parameters.
                encoderParameters = new EncoderParameters(1);

                // Set the quality.
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, quality);
            }
            catch
            {
                if (encoderParameters != null)
                {
                    encoderParameters.Dispose();
                }
            }

            return encoderParameters;
        }
开发者ID:rosrosros,项目名称:ImageProcessor,代码行数:26,代码来源:ImageUtils.cs

示例8: CompressionImage

 public static byte[] CompressionImage(Stream fileStream, long quality)
 {
     using (System.Drawing.Image img = System.Drawing.Image.FromStream(fileStream))
     {
         using (Bitmap bitmap = new Bitmap(img))
         {
             ImageCodecInfo CodecInfo = GetEncoder(img.RawFormat);
             System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
             EncoderParameters myEncoderParameters = new EncoderParameters(1);
             EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, quality);
             myEncoderParameters.Param[0] = myEncoderParameter;
             using (MemoryStream ms = new MemoryStream())
             {
                 bitmap.Save(ms, CodecInfo, myEncoderParameters);
                 myEncoderParameters.Dispose();
                 myEncoderParameter.Dispose();
                 return ms.ToArray();
             }
         }
     }
 }
开发者ID:applenele,项目名称:NewRen,代码行数:21,代码来源:Image.cs

示例9: CaptureWebPageBytesP

        static byte[] CaptureWebPageBytesP(string body, int width, int height)
        {
            byte[] data;

            using (WebBrowser web = new WebBrowser())
            {
                web.ScrollBarsEnabled = false; // no scrollbars
                web.ScriptErrorsSuppressed = true; // no errors

                web.DocumentText = body;
                while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    System.Windows.Forms.Application.DoEvents();

                web.Width = web.Document.Body.ScrollRectangle.Width;
                web.Height = web.Document.Body.ScrollRectangle.Height;

                // a bitmap that we will draw to
                using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(web.Width, web.Height))
                {
                    // draw the web browser to the bitmap
                    web.DrawToBitmap(bmp, new Rectangle(web.Location.X, web.Location.Y, web.Width, web.Height));
                    // draw the web browser to the bitmap

                    GraphicsUnit units = GraphicsUnit.Pixel;
                    RectangleF destRect = new RectangleF(0F, 0F, width, height);
                    RectangleF srcRect = new RectangleF(0, 0, web.Width, web.Width * 1.5F);

                    Bitmap b = new Bitmap(width, height);
                    Graphics g = Graphics.FromImage((Image)b);
                    g.Clear(Color.White);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.DrawImage(bmp, destRect, srcRect, units);
                    g.Dispose();

                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                    {
                        EncoderParameter qualityParam = null;
                        EncoderParameters encoderParams = null;
                        try
                        {
                            ImageCodecInfo imageCodec = null;
                            imageCodec = GetEncoderInfo("image/jpeg");

                            qualityParam = new EncoderParameter(Encoder.Quality, 100L);

                            encoderParams = new EncoderParameters(1);
                            encoderParams.Param[0] = qualityParam;
                            b.Save(stream, imageCodec, encoderParams);
                        }
                        catch (Exception)
                        {
                            throw new Exception();
                        }
                        finally
                        {
                            if (encoderParams != null) encoderParams.Dispose();
                            if (qualityParam != null) qualityParam.Dispose();
                        }
                        b.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Position = 0;
                        data = new byte[stream.Length];
                        stream.Read(data, 0, (int)stream.Length);
                    }
                }
            }
            return data;
        }
开发者ID:clearfunction,项目名称:bvcms,代码行数:68,代码来源:DisplayController.cs

示例10: SaveImage

        protected override void SaveImage(Stream stream, Image image)
        {
            ImageCodecInfo myImageCodecInfo;
            Encoder myEncoder;
            EncoderParameter myEncoderParameter;
            EncoderParameters myEncoderParameters;

            myImageCodecInfo = GetEncoderInfo(EncoderType);
            myEncoder = Encoder.Quality;
            myEncoderParameters = new EncoderParameters(EncoderParameterCount);
            myEncoderParameter = new EncoderParameter(myEncoder, imageQuality);
            myEncoderParameters.Param[0] = myEncoderParameter;

            try
            {
                image.Save(stream, myImageCodecInfo, myEncoderParameters);
            }
            finally
            {
                myEncoderParameters.Dispose();
                myEncoderParameter.Dispose();
            }
        }
开发者ID:pusp,项目名称:o2platform,代码行数:23,代码来源:JpgFormat.cs

示例11: Process

 public System.IO.Stream Process(System.IO.Stream inputStream)
 {
     if (inputStream == null || !inputStream.CanRead)
     {
         throw new System.ArgumentException("inputStream isn't validate", "inputStream");
     }
     inputStream.Seek(0L, System.IO.SeekOrigin.Begin);
     bool flag = false;
     Image image = Image.FromStream(inputStream);
     ImageFormat rawFormat = image.RawFormat;
     if (ImageProcessor.IsGIFAnimation(image))
     {
         inputStream.Seek(0L, System.IO.SeekOrigin.Begin);
         return inputStream;
     }
     foreach (IImageFilter current in this.Filters)
     {
         bool flag2;
         image = current.Process(image, out flag2);
         if (flag2)
         {
             flag = true;
         }
     }
     if (!flag)
     {
         inputStream.Seek(0L, System.IO.SeekOrigin.Begin);
         return inputStream;
     }
     System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
     if (rawFormat.Guid == ImageFormat.Gif.Guid)
     {
         image.Save(memoryStream, ImageFormat.Jpeg);
     }
     else
     {
         EncoderParameters encoderParameters = new EncoderParameters(1);
         encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, (long)this.JpegQuality);
         ImageCodecInfo imageCodecInfo = ImageProcessor.GetImageCodecInfo(rawFormat);
         image.Save(memoryStream, imageCodecInfo, encoderParameters);
         encoderParameters.Dispose();
     }
     memoryStream.Seek(0L, System.IO.SeekOrigin.Begin);
     return memoryStream;
 }
开发者ID:hbulzy,项目名称:SYS,代码行数:45,代码来源:ImageProcessor.cs

示例12: CacheMapTexture

        byte[] CacheMapTexture(int maplayer, int regionX, int regionY, Bitmap mapTexture, bool forced = false)
        {
            if (!forced && IsStaticBlank(mapTexture))
                return m_blankRegionTileData;

            byte[] jpeg;
            EncoderParameters myEncoderParameters = new EncoderParameters();
            myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L);

            using (MemoryStream imgstream = new MemoryStream())
            {
                var encInfo = GetEncoderInfo ("image/jpeg");
                if (encInfo != null) {
                    // Save bitmap to stream
                    lock (mapTexture)
                        mapTexture.Save (imgstream, encInfo, myEncoderParameters);
                }
                // Write the stream to a byte array for output
                jpeg = imgstream.ToArray ();

            }

            myEncoderParameters.Dispose ();
            SaveCachedImage(maplayer, regionX, regionY, jpeg);
            return jpeg;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:26,代码来源:MapService.cs

示例13: OnHTTPGetMapImage

        public byte [] OnHTTPGetMapImage (string path, Stream request, OSHttpRequest httpRequest,
                                        OSHttpResponse httpResponse)
        {
            MainConsole.Instance.Debug ("[World map]: Sending map image jpeg");
            byte [] jpeg = new byte [0];

            MemoryStream imgstream = new MemoryStream ();
            Bitmap mapTexture;
            Image image = null;

            try {
                // Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular jpeg data

                imgstream = new MemoryStream ();

                // non-async because we know we have the asset immediately.
                byte [] mapasset =
                    m_scene.AssetService.GetData (m_scene.RegionInfo.RegionSettings.TerrainImageID.ToString ());
                if (mapasset != null) {
                    image = m_scene.RequestModuleInterface<IJ2KDecoder> ().DecodeToImage (mapasset);
                    // Decode image to System.Drawing.Image
                    if (image != null) {
                        // Save to bitmap
                        mapTexture = (Bitmap)image;

                        EncoderParameters myEncoderParameters = new EncoderParameters ();
                        myEncoderParameters.Param [0] = new EncoderParameter (Encoder.Quality, 95L);
                        var encInfo = GetEncoderInfo ("image/jpeg");

                        if (encInfo != null) {
                            // Save bitmap to stream
                            mapTexture.Save (imgstream, encInfo, myEncoderParameters);
                        }
                        myEncoderParameters.Dispose ();

                        // Write the stream to a byte array for output
                        jpeg = imgstream.ToArray ();
                    }
                }
            } catch (Exception) {
                // Dummy!
                MainConsole.Instance.Warn ("[World map]: Unable to generate Map image");
            } finally {
                // Reclaim memory, these are unmanaged resources
                // If we encountered an exception, one or more of these will be null
                if (image != null)
                    image.Dispose ();

                imgstream.Close ();
            }

            httpResponse.ContentType = "image/jpeg";
            return jpeg;
        }
开发者ID:EnricoNirvana,项目名称:WhiteCore-Dev,代码行数:54,代码来源:WorldMap.cs

示例14: GeneratePreviews

        /// <summary>
        /// Generate prieviews
        /// </summary>
        /// <param name="img"></param>
        protected void GeneratePreviews(Bitmap img)
        {
            int x = MediaFile.Width;
            int y = MediaFile.Height;

            ImageFormat fmt;
            string mime;
            GetPreviewFormat(out fmt, out mime);
            EncoderParameters eparams = new EncoderParameters(1);
            eparams.Param[0] = new EncoderParameter(Encoder.Quality,
                                                    Manager.PreviewQuality);
            ImageCodecInfo ici = Gfx.GetEncoderInfo(mime);
            bool gendefault = false;

            if (x > Manager.PreviewMinWidth || y > Manager.PreviewMinHeight) {
                //Log.Debug("### Generate previews for {0}\n", MediaFile.FullName);
                foreach (Preview p in Manager.Previews) {
                    if (x < p.Width && y < p.Height) {
                        if (p.Name == "medium")
                            gendefault = true;
                        continue;
                    }
                    PreviewFile pf = lowGenImg(ref img, p, fmt, mime, ici, eparams);
                    MediaFile.Previews.Add(pf);
                }
            }
            else {
                gendefault = true;
            }

            if (gendefault) {
                Preview p = new Preview();
                p.Width = img.Width;
                p.Height = img.Height;
                p.Name = "default";

                PreviewFile pf = lowGenImg(ref img, p, fmt, mime, ici, eparams);
                MediaFile.Previews.Add(pf);
            }

            eparams.Dispose();
            eparams = null;
            ici = null;
            fmt = null;
        }
开发者ID:poppa,项目名称:MediaDB,代码行数:49,代码来源:FileHandler.cs

示例15: CutForSquare

        /// <summary>
        /// 正方型裁剪
        /// 以图片中心为轴心,截取正方型,然后等比缩放
        /// 用于头像处理
        /// </summary>
        /// <remarks>吴剑 2010-11-23</remarks>
        /// <param name="postedFile">原图HttpPostedFile对象</param>
        /// <param name="fileSaveUrl">缩略图存放地址</param>
        /// <param name="side">指定的边长(正方型)</param>
        /// <param name="quality">质量(范围0-100)</param>
        public static void CutForSquare(System.IO.Stream fromFile, string fileSaveUrl, int side, int quality)
        {
            //创建目录
            string dir = Path.GetDirectoryName(fileSaveUrl);
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
            System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);

            //原图宽高均小于模版,不作处理,直接保存
            if (initImage.Width <= side && initImage.Height <= side)
            {
                initImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                //原始图片的宽、高
                int initWidth = initImage.Width;
                int initHeight = initImage.Height;

                //非正方型先裁剪为正方型
                if (initWidth != initHeight)
                {
                    //截图对象
                    System.Drawing.Image pickedImage = null;
                    System.Drawing.Graphics pickedG = null;

                    //宽大于高的横图
                    if (initWidth > initHeight)
                    {
                        //对象实例化
                        pickedImage = new System.Drawing.Bitmap(initHeight, initHeight);
                        pickedG = System.Drawing.Graphics.FromImage(pickedImage);
                        //设置质量
                        pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        //定位
                        Rectangle fromR = new Rectangle((initWidth - initHeight) / 2, 0, initHeight, initHeight);
                        Rectangle toR = new Rectangle(0, 0, initHeight, initHeight);
                        //画图
                        pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
                        //重置宽
                        initWidth = initHeight;
                    }
                    //高大于宽的竖图
                    else
                    {
                        //对象实例化
                        pickedImage = new System.Drawing.Bitmap(initWidth, initWidth);
                        pickedG = System.Drawing.Graphics.FromImage(pickedImage);
                        //设置质量
                        pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        //定位
                        Rectangle fromR = new Rectangle(0, (initHeight - initWidth) / 2, initWidth, initWidth);
                        Rectangle toR = new Rectangle(0, 0, initWidth, initWidth);
                        //画图
                        pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
                        //重置高
                        initHeight = initWidth;
                    }

                    //将截图对象赋给原图
                    initImage = (System.Drawing.Image)pickedImage.Clone();
                    //释放截图资源
                    pickedG.Dispose();
                    pickedImage.Dispose();
                }

                //缩略图对象
                System.Drawing.Image resultImage = new System.Drawing.Bitmap(side, side);
                System.Drawing.Graphics resultG = System.Drawing.Graphics.FromImage(resultImage);
                //设置质量
                resultG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                resultG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //用指定背景色清空画布
                resultG.Clear(Color.White);
                //绘制缩略图
                resultG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, side, side), new System.Drawing.Rectangle(0, 0, initWidth, initHeight), System.Drawing.GraphicsUnit.Pixel);

                //关键质量控制
                //获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
                ImageCodecInfo[] icis = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo ici = null;
                foreach (ImageCodecInfo i in icis)
                {
                    if (i.MimeType == "image/jpeg" || i.MimeType == "image/bmp" || i.MimeType == "image/png" || i.MimeType == "image/gif")
                    {
                        ici = i;
//.........这里部分代码省略.........
开发者ID:441023065,项目名称:CMS,代码行数:101,代码来源:ImageProcessing.cs


注:本文中的System.Drawing.Imaging.EncoderParameters.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。