當前位置: 首頁>>代碼示例>>C#>>正文


C# Image.Dispose方法代碼示例

本文整理匯總了C#中System.Drawing.Image.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# Image.Dispose方法的具體用法?C# Image.Dispose怎麽用?C# Image.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Image的用法示例。


在下文中一共展示了Image.Dispose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Add

        public void Add(Image img)
        {
            _list.Add(GetBytes(img));

            // stored image data, now dispose of original
            img.Dispose();
        }
開發者ID:731jerry,項目名稱:GZBClient,代碼行數:7,代碼來源:PageImageList.cs

示例2: DetectAndTrimFace

        public static Image<Gray, byte> DetectAndTrimFace(int[] pixels, Size initialSize, Size outputSize, String haarcascadePath)
        {
            var inBitmap = ConvertToBitmap(pixels, initialSize.Width, initialSize.Width);

            //for testing purposes I can the picture to a folder
            //inBitmap.Save(@"E:\data\phototest\received.bmp");

            var grayframe = new Image<Gray, byte>(inBitmap);

            var haar = new HaarCascade(haarcascadePath);
            var faces = haar.Detect(grayframe,
                1.2,
                3,
                HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                new Size(30, 30));

            if (faces.Count() != 1)
            {
                return null;
            }
            var face = faces[0];

            var returnImage = grayframe.Copy(face.rect).Resize(outputSize.Width, outputSize.Height, INTER.CV_INTER_CUBIC);

            //cleanup managed resources
            haar.Dispose();
            grayframe.Dispose();

            return returnImage;
        }
開發者ID:al-main,項目名稱:CloudyBank,代碼行數:30,代碼來源:ImageProcessingUtils.cs

示例3: Crop

 public static Image Crop(Image originalImage, RectangleF rect)
 {
     Bitmap bmpImage = new Bitmap(originalImage);
     Bitmap bmpCrop = bmpImage.Clone(rect, bmpImage.PixelFormat);
     originalImage.Dispose();
     return (Image)(bmpCrop);
 }
開發者ID:cairabbit,項目名稱:daf,代碼行數:7,代碼來源:ImageHelper.cs

示例4: ResizeImage

        /// <summary>
        /// resmi yeniden boyutlandır.
        /// </summary>
        /// <param name="imgToResize">boyutlandırılacak resim</param>
        /// <param name="size">boyutlar</param>
        /// <returns>Image titipnde bir resim</returns>
        public static Image ResizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();
            imgToResize.Dispose();

            return (Image)b;
        }
開發者ID:murat0058,項目名稱:NewsSite,代碼行數:36,代碼來源:ImageManager.cs

示例5: ResizeImage

        public static Image ResizeImage(double scaleFactor, Image image)
        {
            MemoryStream stream = new MemoryStream();

            var newWidth = (int)(image.Width * scaleFactor);
            var newHeight = (int)(image.Height * scaleFactor);
            var thumbnailBitmap = new Bitmap(newWidth, newHeight);

            var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
            thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbnailGraph.DrawImage(image, imageRectangle);

            thumbnailBitmap.Save(stream, image.RawFormat);

            Image returnImage = Image.FromStream(stream);

            thumbnailGraph.Dispose();
            thumbnailBitmap.Dispose();
            image.Dispose();

            return returnImage;
        }
開發者ID:Mahdi-K,項目名稱:KCore,代碼行數:26,代碼來源:ImageUtils.cs

示例6: TakeScreenshot

        /// <summary>
        /// Most of the time it just returns a black screen, this is because the game is rendering straight to the 
        /// graphics card using directx and bypassing whatever windows usually uses for PrintWindow 
        /// AFAIK directx screenshots only work if the window is currently visible (not overlaid by the bot itself)
        /// </summary>
        /// <returns></returns>
        public Image<Bgr, byte> TakeScreenshot()
        {
            Bitmap frame = new Bitmap(1024, 768);
            using (Graphics g = Graphics.FromImage(frame))
            {
                IntPtr deviceContextHandle = g.GetHdc();
                PrintWindow(GetGameWindowHandle(), deviceContextHandle, 1);
                g.ReleaseHdc();
            }
            //we have the bitmap now
            //turn it into an Image for emgu
            BitmapData bmpData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadWrite,
                                                PixelFormat.Format24bppRgb);

            Image<Bgr, byte> tempImage = new Image<Bgr, byte>(frame.Width, frame.Height, bmpData.Stride, bmpData.Scan0);
            //to prevent any corrupted memory errors that crop up for some reason
            Image<Bgr, byte> image = tempImage.Clone();
            frame.UnlockBits(bmpData);
            //dispose all unused image data to prevent memory leaks
            frame.Dispose();
            tempImage.Dispose();
            image.Save("screenshot.png");

            return image;
        }
開發者ID:doskir,項目名稱:Bejeweled3Bot,代碼行數:31,代碼來源:GameWindow.cs

示例7: ConvertTiffToBitmap

            /// <summary>
            /// Convert Tiff image to another mime-type bitmap
            /// </summary>
            /// <param name="tiffImage">Source TIFF file</param>
            /// <param name="mimeType">Desired result mime-type</param>
            /// <returns>Converted image</returns>
            public Bitmap ConvertTiffToBitmap(Image tiffImage, string mimeType)
            {
                var imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(encoder => encoder.MimeType == "image/tiff");

                if (imageCodecInfo == null)
                {
                    return null;
                }
                Bitmap sourceImg;

                using (var memoryStream = new MemoryStream())
                {
                    // Setting encode params
                    var imageEncoderParams = new EncoderParameters(1);
                    imageEncoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    tiffImage.Save(memoryStream, imageCodecInfo, imageEncoderParams);
                    tiffImage.Dispose();

                    var ic = new ImageConverter();

                    // Reading stream data to new image
                    var tempTiffImage = (Image)ic.ConvertFrom(memoryStream.GetBuffer());

                    // Setting new result mime-type
                    imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(encoder => encoder.MimeType == mimeType);
                    if (tempTiffImage != null) tempTiffImage.Save(memoryStream, imageCodecInfo, imageEncoderParams);

                    sourceImg = new Bitmap(Image.FromStream(memoryStream, true));

                }

                return sourceImg;
            }
開發者ID:petersgiles,項目名稱:Converty,代碼行數:39,代碼來源:Program.cs

示例8: Process

 public Image Process(Image inputImage, out bool isProcessed)
 {
     if (this.TargetSize.Height > inputImage.Height && this.TargetSize.Width > inputImage.Width)
     {
         isProcessed = false;
         return inputImage;
     }
     Size arg_39_0 = inputImage.Size;
     Rectangle cropArea = this.CropArea;
     int num = cropArea.X + cropArea.Width;
     if (num > inputImage.Width)
     {
         cropArea.Width -= num - inputImage.Width;
     }
     int num2 = cropArea.Y + cropArea.Height;
     if (num2 > inputImage.Height)
     {
         cropArea.Height -= num2 - inputImage.Height;
     }
     Bitmap bitmap = new Bitmap(this.TargetSize.Width, this.TargetSize.Height);
     using (Graphics graphics = Graphics.FromImage(bitmap))
     {
         graphics.InterpolationMode = this.InterpoliationMode;
         graphics.SmoothingMode = this.SmoothingMode;
         Rectangle destRect = new Rectangle(0, 0, this.TargetSize.Width, this.TargetSize.Height);
         graphics.DrawImage(inputImage, destRect, cropArea, GraphicsUnit.Pixel);
     }
     inputImage.Dispose();
     isProcessed = true;
     return bitmap;
 }
開發者ID:hbulzy,項目名稱:SYS,代碼行數:31,代碼來源:CropFilter.cs

示例9: CheckValidImage

 public Image CheckValidImage(Image img, int width, int height)
 {
     if (img == null) return null;
     Bitmap bmp = new Bitmap(width, height);
     try
     {
         using (Graphics g = Graphics.FromImage(bmp))
         {
             g.InterpolationMode = InterpolationMode.HighQualityBicubic;
             g.PixelOffsetMode = PixelOffsetMode.HighQuality;
             g.DrawImage(img, 0, 0, width, height);
         }
         bmp.Tag = img.Tag;
         return bmp;
     }
     catch (Exception)
     {
         bmp.Dispose();
         bmp = new Bitmap(width, height);
         bmp.Tag = img.Tag;
         return bmp;
     }
     finally
     {
         img.Dispose();
     }
 }
開發者ID:egtra,項目名稱:OpenTween,代碼行數:27,代碼來源:HttpVarious.cs

示例10: Main

 static void Main(string[] args)
 {
     var img = new Image<Bgr, byte>(@"src.jpg");
     var w = img.Width;
     var h = img.Height;
     var r0 = 512;   // half of the image size
     var p = 0.5;    // control the "height"
     var phi0 = -Math.PI / 2 + 0.12;    // initial phase
     var newImg = new Image<Bgr, byte>(r0 * 2, r0 * 2, new Bgr(Color.White));
     for (int row = 0; row < r0 * 2; row++)
     {
         for (int col = 0; col < r0 * 2; col++)
         {
             var phi = (Math.Atan2(row - r0, col - r0) + phi0);
             if (phi > Math.PI) phi -= 2 * Math.PI;
             if (phi < -Math.PI) phi += 2 * Math.PI;
             var r = Math.Sqrt((row - r0) * (row - r0) + (col - r0) * (col - r0));
             r = Math.Pow(r0, 1 - p) * Math.Pow(r, p);
             var y = (int)(h - r / r0 * h);
             var x = (int)((phi + Math.PI) / Math.PI / 2 * w);
             if (y >= 0 && y < h && x >= 0 && x < w)
                 newImg[row, col] = img[y, x];
         }
     }
     newImg.Save("result.jpg");
     newImg.Dispose();
     img.Dispose();
 }
開發者ID:grapeot,項目名稱:SmallWorldPanorama,代碼行數:28,代碼來源:Program.cs

示例11: PagingImage

 public PagingImage(string filename)
 {
     _filename = filename;
     img = Bitmap.FromFile(filename);
     _pages = img.GetFrameCount(FrameDimension.Page);
     img.Dispose();
 }
開發者ID:liorg,項目名稱:DesignPatternsForXrm,代碼行數:7,代碼來源:PagingImage.cs

示例12: Crop

        public static Image Crop(Image Image, int newWidth, int newHeight, int startX = 0, int startY = 0)
        {
            if (Image.Height < newHeight)
                newHeight = Image.Height;

            if (Image.Width < newWidth)
                newWidth = Image.Width;

            using (var bmp = new Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb))
            {
                bmp.SetResolution(72, 72);
                using (var g = Graphics.FromImage(bmp))
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.DrawImage(Image, new Rectangle(0, 0, newWidth, newHeight), startX, startY, newWidth, newHeight, GraphicsUnit.Pixel);

                    var ms = new MemoryStream();
                    bmp.Save(ms, ImageFormat.Png);
                    Image.Dispose();
                    var outimage = Image.FromStream(ms);
                    return outimage;
                }
            }
        }
開發者ID:ServiceStackApps,項目名稱:AwsApps,代碼行數:26,代碼來源:ImageService.cs

示例13: ParseImage

        public int[][] ParseImage(Image pic)
        {
            Bitmap bitmapPic = new Bitmap(this.MATRIX_WIDTH, this.MATRIX_HEIGHT);

            // cut smallest square around the letter
            Rectangle letterSquare = this.TrimLetter(new Bitmap(pic));

            // resize it
            Graphics graphics = Graphics.FromImage(bitmapPic);
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            graphics.DrawImage(pic,
                new Rectangle(0, 0, this.MATRIX_WIDTH, this.MATRIX_HEIGHT),
                letterSquare,
                GraphicsUnit.Pixel);

            // convert data to int[][]
            int[][] resultMatrix = this.DataToString(ref bitmapPic);

            graphics.Dispose();
            bitmapPic.Dispose();
            pic.Dispose();

            return resultMatrix;
        }
開發者ID:bladespinner,項目名稱:AI-Course-Project,代碼行數:28,代碼來源:ImageToNetworkInput.cs

示例14: ResizeImage

		public static Image ResizeImage (Image img, string path, Size maxSize) {
			// Mono for mac uses a better system.drawing implementation; fall back to graphicsmagick on linux
			if (Extensions.IsRunningOnMac) {
				var maxAspect = (float)maxSize.Width / (float)maxSize.Height;
				var imgAspect = (float)img.Width / (float)img.Height;

				if (imgAspect > maxAspect)
					return new Bitmap(img, new Size(maxSize.Width, (int)Math.Round(maxSize.Width / imgAspect)));
				else
					return new Bitmap(img, new Size((int)Math.Round(maxSize.Height * imgAspect), maxSize.Height));
			} else {
				img.Dispose();
				var wand = GraphicsMagick.NewWand();
				GraphicsMagick.ReadImageBlob(wand, File.OpenRead(path));

				var maxAspect = (float)maxSize.Width / (float)maxSize.Height;
				var imgAspect = (float)GraphicsMagick.GetWidth(wand) / (float)GraphicsMagick.GetHeight(wand);

				if (imgAspect > maxAspect)
					GraphicsMagick.ResizeImage(wand, (IntPtr)maxSize.Width, (IntPtr)Math.Round(maxSize.Width / imgAspect), GraphicsMagick.Filter.Box, 1);
				else
					GraphicsMagick.ResizeImage(wand, (IntPtr)Math.Round(maxSize.Height * imgAspect), (IntPtr)maxSize.Height, GraphicsMagick.Filter.Box, 1);
				var newImgBlob = GraphicsMagick.WriteImageBlob(wand);

				using (var ms = new MemoryStream(newImgBlob)) {
					return Image.FromStream(ms);
				}
			}
		}
開發者ID:jpernst,項目名稱:GameStack,代碼行數:29,代碼來源:ImageHelper.cs

示例15: MakeSquareImage

        public static void MakeSquareImage(Image image, string newFileName, int newSize)
        {
            int width = image.Width;
            int height = image.Height;

            var b = new Bitmap(newSize, newSize);

            try
            {
                Graphics g = Graphics.FromImage(b);
                g.InterpolationMode = InterpolationMode.High;
                g.SmoothingMode = SmoothingMode.HighQuality;

                g.Clear(Color.Transparent);
                g.DrawImage(image, new Rectangle(0, 0, newSize, newSize),
                            width < height
                                ? new Rectangle(0, (height - width)/2, width, width)
                                : new Rectangle((width - height)/2, 0, height, height), GraphicsUnit.Pixel);

                SaveImage(b, newFileName, GetCodecInfo("image/" + GetFormat(newFileName).ToString().ToLower()));
            }
            finally
            {
                image.Dispose();
                b.Dispose();
            }
        }
開發者ID:the404,項目名稱:yqblog,代碼行數:27,代碼來源:Thumbnail.cs


注:本文中的System.Drawing.Image.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。