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


C# ImageAttributes.Dispose方法代码示例

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


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

示例1: DrawBackgroundImage

 public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (backgroundImageLayout == ImageLayout.Tile)
     {
         using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
         {
             if (scrollOffset != Point.Empty)
             {
                 Matrix transform = brush.Transform;
                 transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y);
                 brush.Transform = transform;
             }
             g.FillRectangle(brush, clipRect);
             return;
         }
     }
     Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
     if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
     {
         rect.X += clipRect.Width - rect.Width;
     }
     using (SolidBrush brush2 = new SolidBrush(backColor))
     {
         g.FillRectangle(brush2, clipRect);
     }
     if (!clipRect.Contains(rect))
     {
         if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
         {
             rect.Intersect(clipRect);
             g.DrawImage(backgroundImage, rect);
         }
         else if (backgroundImageLayout == ImageLayout.None)
         {
             rect.Offset(clipRect.Location);
             Rectangle destRect = rect;
             destRect.Intersect(clipRect);
             Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
             g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
         }
         else
         {
             Rectangle rectangle4 = rect;
             rectangle4.Intersect(clipRect);
             Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
             g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
         }
     }
     else
     {
         ImageAttributes imageAttr = new ImageAttributes();
         imageAttr.SetWrapMode(WrapMode.TileFlipXY);
         g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
         imageAttr.Dispose();
     }
 }
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:60,代码来源:CmbControlPaintEx.cs

示例2: AdjustBrightness

        public static Bitmap AdjustBrightness(this Image Image, Color contrastMultiplier, Color brightnessBonus)
        {
            var TempBitmap = Image;
            var NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
            var NewGraphics = Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix = {
                                             new[] { contrastMultiplier.R/255.0f, 0, 0, 0, 0 }, new[] { 0, contrastMultiplier.G/255.0f, 0, 0, 0 },
                                             new[] { 0, 0, contrastMultiplier.B/255.0f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 },
                                             new[] { brightnessBonus.R/255.0f, brightnessBonus.G/255.0f, brightnessBonus.B/255.0f, 1, 1 }
                                         };

            var NewColorMatrix = new ColorMatrix(FloatColorMatrix);
            var Attributes = new ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap,
                                  new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height),
                                  0,
                                  0,
                                  TempBitmap.Width,
                                  TempBitmap.Height,
                                  GraphicsUnit.Pixel,
                                  Attributes);
            Attributes.Dispose();
            NewGraphics.Dispose();
            return NewBitmap;
        }
开发者ID:Jamanno,项目名称:Zero-K-Infrastructure,代码行数:26,代码来源:Images.cs

示例3: Set

        public static Image Set(Image image, float opacity)
        {
            Bitmap bmp = new Bitmap(image.Width, image.Height);
            Graphics gfx = Graphics.FromImage(bmp);
            ColorMatrix cmx = new ColorMatrix();
            cmx.Matrix33 = opacity;

            ImageAttributes ia = new ImageAttributes();
            ia.SetColorMatrix(cmx, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, ia);
            ia.Dispose();
            gfx.Dispose();

            return bmp;
        }
开发者ID:r4dius,项目名称:AutoPuTTY,代码行数:15,代码来源:ImageOpacity.cs

示例4: ApplyColorMatrix

		private static void ApplyColorMatrix(Bitmap b , ref ColorMatrix matrix)
		{
		
			ImageAttributes ImgAtt = new ImageAttributes();
			//Bitmap bmpMatrix=new Bitmap(b.Width, b.Height);
			Graphics grMatrix = Graphics.FromImage(b);
																	
			ImgAtt.SetColorMatrix(matrix);

			grMatrix.DrawImage(b, new Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, ImgAtt);
		
			//b = bmpMatrix;

			grMatrix.Dispose();
			ImgAtt.Dispose();
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:16,代码来源:Filters.cs

示例5: AdjustBrightness

        public static Bitmap AdjustBrightness(Bitmap Image, int Value)
        {
            Bitmap TempBitmap = Image;
            float FinalValue = (float)Value / 255.0f;
            Bitmap NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
            Graphics NewGraphics = Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix = {
                        new float[] {1, 0, 0, 0, 0},
                        new float[] {0, 1, 0, 0, 0},
                        new float[] {0, 0, 1, 0, 0},
                        new float[] {0, 0, 0, 1, 0},
                        new float[] {FinalValue, FinalValue, FinalValue, 1, 1}
                    };

            ColorMatrix NewColorMatrix = new ColorMatrix(FloatColorMatrix);
            ImageAttributes Attributes = new ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap, new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, GraphicsUnit.Pixel, Attributes);
            Attributes.Dispose();
            NewGraphics.Dispose();
            return NewBitmap;
        }
开发者ID:Strongelhold,项目名称:ImageProcessor,代码行数:22,代码来源:Form1.cs

示例6: DrawImageColorized

 private static void DrawImageColorized(Graphics graphics, Image image, Rectangle destination, ColorMatrix matrix)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     ImageAttributes imageAttrs = new ImageAttributes();
     imageAttrs.SetColorMatrix(matrix);
     graphics.DrawImage(image, destination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttrs, null, IntPtr.Zero);
     imageAttrs.Dispose();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:ControlPaint.cs

示例7: MakeTransparent

 private static void MakeTransparent(string p)
 {
     FileStream fs = new FileStream(p, FileMode.Open, FileAccess.Read);
     MemoryStream ms = new MemoryStream();
     fs.CopyTo(ms);
     ms.Position = 0;
     fs.Close();
     using (Image original = new Bitmap(ms))
     {
         using (Bitmap image = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb))
         {
             Graphics g = Graphics.FromImage(image);
             ImageAttributes ia = new ImageAttributes();
             ia.SetColorKey(Color.FromArgb(0, 0xde, 0), Color.FromArgb(33, 255, 5));
             g.DrawImage(
                 original,
                 new Rectangle(0, 0, original.Width, original.Height),
                 0,
                 0,
                 original.Width,
                 original.Height,
                 GraphicsUnit.Pixel,
                 ia);
             image.Save(p, ImageFormat.Png);
             g.Dispose();
             ia.Dispose();
         }
     }
 }
开发者ID:CellAO,项目名称:CellAO-NightPredator,代码行数:29,代码来源:Program.cs

示例8: AddImageSignPic


//.........这里部分代码省略.........
                int y = 0;
                switch (watermarkStatus)
                {
                    case 1:
                        x = (int) (img.Width * 0.01f);
                        y = (int) (img.Height * 0.01f);
                        break;

                    case 2:
                        x = ((int) (img.Width * 0.5f)) - (image.Width / 2);
                        y = (int) (img.Height * 0.01f);
                        break;

                    case 3:
                        x = ((int) (img.Width * 0.99f)) - image.Width;
                        y = (int) (img.Height * 0.01f);
                        break;

                    case 4:
                        x = (int) (img.Width * 0.01f);
                        y = ((int) (img.Height * 0.5f)) - (image.Height / 2);
                        break;

                    case 5:
                        x = ((int) (img.Width * 0.5f)) - (image.Width / 2);
                        y = ((int) (img.Height * 0.5f)) - (image.Height / 2);
                        break;

                    case 6:
                        x = ((int) (img.Width * 0.99f)) - image.Width;
                        y = ((int) (img.Height * 0.5f)) - (image.Height / 2);
                        break;

                    case 7:
                        x = (int) (img.Width * 0.01f);
                        y = ((int) (img.Height * 0.99f)) - image.Height;
                        break;

                    case 8:
                        x = ((int) (img.Width * 0.5f)) - (image.Width / 2);
                        y = ((int) (img.Height * 0.99f)) - image.Height;
                        break;

                    case 9:
                        x = ((int) (img.Width * 0.99f)) - image.Width;
                        y = ((int) (img.Height * 0.99f)) - image.Height;
                        break;
                }
                graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
                ImageCodecInfo[] imageEncoders = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo encoder = null;
                foreach (ImageCodecInfo info2 in imageEncoders)
                {
                    if (info2.MimeType.IndexOf("jpeg") > -1)
                    {
                        encoder = info2;
                    }
                }
                EncoderParameters encoderParams = new EncoderParameters();
                long[] numArray2 = new long[1];
                if ((quality < 0) || (quality > 100))
                {
                    quality = 80;
                }
                numArray2[0] = quality;
                EncoderParameter parameter = new EncoderParameter(Encoder.Quality, numArray2);
                encoderParams.Param[0] = parameter;
                stream = new MemoryStream();
                if (encoder != null)
                {
                    img.Save(stream, encoder, encoderParams);
                }
                stream2 = stream;
            }
            catch
            {
                stream = null;
                stream2 = stream;
            }
            finally
            {
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                if (img != null)
                {
                    img.Dispose();
                }
                if (image != null)
                {
                    image.Dispose();
                }
                if (imageAttr != null)
                {
                    imageAttr.Dispose();
                }
            }
            return stream2;
        }
开发者ID:ZhangVic,项目名称:asp1110git,代码行数:101,代码来源:PIC.cs

示例9: ImageWaterMarkPic


//.........这里部分代码省略.........
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            if (watermark.Height >= sourceImg.Height || watermark.Width >= sourceImg.Width)
                throw new Exception("水印图片大于原图");

            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();

            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float transparency = 0.5F;
            if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
                transparency = (watermarkTransparency / 10.0F);

            float[][] colorMatrixElements = {
                                                new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  transparency, 0.0f},
                                                new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                            };

            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;

            switch (watermarkStatus)
            {
                case 1:
                    xpos = (int)(sourceImg.Width * (float).01);
                    ypos = (int)(sourceImg.Height * (float).01);
                    break;
                case 2:
                    xpos = (int)((sourceImg.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)(sourceImg.Height * (float).01);
                    break;
                case 3:
                    xpos = (int)((sourceImg.Width * (float).99) - (watermark.Width));
                    ypos = (int)(sourceImg.Height * (float).01);
                    break;
                case 4:
                    xpos = (int)(sourceImg.Width * (float).01);
                    ypos = (int)((sourceImg.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 5:
                    xpos = (int)((sourceImg.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((sourceImg.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 6:
                    xpos = (int)((sourceImg.Width * (float).99) - (watermark.Width));
                    ypos = (int)((sourceImg.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 7:
                    xpos = (int)(sourceImg.Width * (float).01);
                    ypos = (int)((sourceImg.Height * (float).99) - watermark.Height);
                    break;
                case 8:
                    xpos = (int)((sourceImg.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((sourceImg.Height * (float).99) - watermark.Height);
                    break;
                case 9:
                    xpos = (int)((sourceImg.Width * (float).99) - (watermark.Width));
                    ypos = (int)((sourceImg.Height * (float).99) - watermark.Height);
                    break;
            }

            g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);

            ImageCodecInfo ici = SunImgFormat.GetImageCodecInfo(imgExt);
            EncoderParameters encoderParams = new EncoderParameters();
            long[] qualityParam = new long[1];
            if (quality < 0 || quality > 100)
                quality = 80;

            qualityParam[0] = quality;

            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
            encoderParams.Param[0] = encoderParam;
            MemoryStream newMS = new MemoryStream();
            if (ici != null)
                sourceImg.Save(newMS, ici, encoderParams);
            else
                sourceImg.Save(newMS,tFormat);

            watermarkImg.Dispose();//释放资源
            sourceImgMS.Dispose();//释放资源
            g.Dispose();
            sourceImg.Dispose();
            watermark.Dispose();
            imageAttributes.Dispose();
            return newMS;
        }
开发者ID:wangscript,项目名称:sunmvc,代码行数:101,代码来源:SunImgWater.cs

示例10: ResizeImage

        /// <summary>
        /// Resizes the specified image to the specifed size.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width in pixels of the resized image.</param>
        /// <param name="height">The height in pixels of the resized image.</param>
        /// <param name="dispose">The value indicating whether to dispose the specified image after returning the new resized bitmap.</param>
        /// <returns>The specifed image, resized to the specified size.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when 'image' is null.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Thrown when 'width' is less than 0.
        ///  - OR -
        /// Thrown when 'height' is less than 0.
        /// </exception>
        public static Bitmap ResizeImage(Image image, int width, int height, bool dispose = true)
        {
            // http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp

            if (image == null)
                throw new ArgumentNullException(nameof(image));
            if (width < 0)
                throw new ArgumentOutOfRangeException(nameof(width), width, "'" + nameof(width) + "' cannot be less than 0.");
            if (height < 0)
                throw new ArgumentOutOfRangeException(nameof(height), height, "'" + nameof(height) + "' cannot be less than 0.");

            Bitmap bitmap = new Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(bitmap);
            ImageAttributes attributes = new ImageAttributes();

            #region >> Sets settings for high quality resizing

            bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            attributes.SetWrapMode(WrapMode.TileFlipXY);

            #endregion
            graphics.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);

            if (dispose) image.Dispose();
            graphics.Dispose();
            attributes.Dispose();

            return bitmap;
        }
开发者ID:mrGyzzz,项目名称:Certus,代码行数:50,代码来源:BitmapUtility.cs

示例11: SetGamma

        /// <summary>
        /// Redraw image into itself using the given gamma correction. 0.1 to 5.0 are allowed. 2.0 produces no change
        /// </summary>
        /// <param name="source"></param>
        /// <param name="luminance"></param>
        public static void SetGamma(Image source, float _gamma)
        {
            // clamp to range

            float gamma = Math.Max(0.1f, Math.Min(_gamma, 5.0f));

            // create image attributes

            ImageAttributes ia = new ImageAttributes();

            ia.SetGamma(gamma);

            // get a graphics for source image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // create destination rectangle

            Rectangle d = new Rectangle(0, 0, source.Width, source.Height);

            // paint into self

            g.DrawImage(source, d, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            // cleanup

            ia.Dispose();

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:45,代码来源:ImageUtility.cs

示例12: SetBrightness

        /// <summary>
        /// Uniformly scale RGB channels to change brightness. useful values are -1 to 1 with 0.0f
        /// causing no change
        /// </summary>
        /// <param name="source"></param>
        /// <param name="luminance"></param>
        public static void SetBrightness(Image source, float bt)
        {
            // create image attributes

            ImageAttributes ia = new ImageAttributes();

            // create color matrix used to scale the channels

            ColorMatrix cm = new ColorMatrix();

            cm[0, 0] = 1.0f; cm[0, 1] = 0.0f; cm[0, 2] = 0.0f; cm[0, 3] = 0.0f; cm[0, 4] = 0.0f;
            cm[1, 0] = 0.0f; cm[1, 1] = 1.0f; cm[1, 2] = 0.0f; cm[1, 3] = 0.0f; cm[1, 4] = 0.0f;
            cm[2, 0] = 0.0f; cm[2, 1] = 0.0f; cm[2, 2] = 1.0f; cm[2, 3] = 0.0f; cm[2, 4] = 0.0f;
            cm[3, 0] = 0.0f; cm[3, 1] = 0.0f; cm[3, 2] = 0.0f; cm[3, 3] = 1.0f; cm[3, 4] = 0.0f;
            cm[4, 0] = bt; cm[4, 1] = bt; cm[4, 2] = bt; cm[4, 3] = 0.0f; cm[4, 4] = 1.0f;

            // set matrix into attributes

            ia.SetColorMatrix(cm);

            // get a graphics for source image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // create destination rectangle

            Rectangle d = new Rectangle(0, 0, source.Width, source.Height);

            // paint into self

            g.DrawImage(source, d, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            // cleanup

            ia.Dispose();

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:54,代码来源:ImageUtility.cs

示例13: GrayScaleImage

        public static void GrayScaleImage(Image source, float lum)
        {
            // create image attributes to blit image into itself with.

            ImageAttributes ia = new ImageAttributes();

            // create gray scale color matrix that will also translate colors according to brightness.
            // NOTE: The alpha translate is 0.0 so that transparent pixels will be unaffected.

            ColorMatrix cm = new ColorMatrix();

            cm[0, 0] = kR; cm[0, 1] = kR; cm[0, 2] = kR; cm[0, 3] = 0.0f; cm[0, 4] = 0.0f;
            cm[1, 0] = kG; cm[1, 1] = kG; cm[1, 2] = kG; cm[1, 3] = 0.0f; cm[1, 4] = 0.0f;
            cm[2, 0] = kB; cm[2, 1] = kB; cm[2, 2] = kB; cm[2, 3] = 0.0f; cm[2, 4] = 0.0f;
            cm[3, 0] = 0.000f; cm[3, 1] = 0.000f; cm[3, 2] = 0.000f; cm[3, 3] = 1.0f; cm[3, 4] = 0.0f;
            cm[4, 0] = lum; cm[4, 1] = lum; cm[4, 2] = lum; cm[4, 3] = 0.0f; cm[4, 4] = 1.0f;

            // associate matrix with attributes

            ia.SetColorMatrix(cm);

            // get a graphics for source image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // create destination rectangle

            Rectangle d = new Rectangle(0, 0, source.Width, source.Height);

            // paint into self

            g.DrawImage(source, d, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            // cleanup

            ia.Dispose();

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:49,代码来源:ImageUtility.cs

示例14: AddImageWatermark


//.........这里部分代码省略.........
                g.DrawImage(img, 0, 0, img.Width, img.Height);
            }
            //设置高质量插值法
            //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Image watermark = new Bitmap(watermarkPath);

            if (watermark.Height >= img.Height || watermark.Width >= img.Width)
            {
                try
                {
                    return AddImageSignText(img, "易车网", watermarkStatus, 80, "Tahoma", 12);
                }
                catch (Exception)
                {
                }
            }

            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();

            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float transparency = 0.5F;
            if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
            {
                transparency = (watermarkTransparency / 10.0F);
            }

            float[][] colorMatrixElements = {
												new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
												new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
												new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
												new float[] {0.0f,  0.0f,  0.0f,  transparency, 0.0f},
												new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
											};

            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            int xpos = 0;
            int ypos = 0;

            switch (watermarkStatus)
            {
                case 1:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 2:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 3:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)(img.Height * (float).01);
                    break;
                case 4:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 5:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 6:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                    break;
                case 7:
                    xpos = (int)(img.Width * (float).01);
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 8:
                    xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
                case 9:
                    xpos = (int)((img.Width * (float).99) - (watermark.Width));
                    ypos = (int)((img.Height * (float).99) - watermark.Height);
                    break;
            }

            g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);
            MemoryStream s = new MemoryStream();
            img.Save(s, GDI.GetEncoder(ImageFormat.Jpeg), GDI.LosslessParam);

            g.Dispose();
            img.Dispose();
            watermark.Dispose();
            imageAttributes.Dispose();

            return s;
        }
开发者ID:besile,项目名称:jita,代码行数:101,代码来源:com_UploadHelper.cs

示例15: ContrastTrackBar_Scroll

        private void ContrastTrackBar_Scroll(object sender, EventArgs e)
        {
            contrast = 0.04f * ContrastTrackBar.Value;

            Bitmap bmp = new Bitmap(picture.Width, picture.Height);

            Graphics g = Graphics.FromImage(bmp);
            ImageAttributes imageAttr = new ImageAttributes();

            ColorMatrix cm = new ColorMatrix(new float[][] {
                                  new float[]{contrast,0f,0f,0f,0f},
                                  new float[]{0f,contrast,0f,0f,0f},
                                  new float[]{0f,0f,contrast,0f,0f},
                                  new float[]{0f,0f,0f,1f,0f},

                                  new float[]{0.001f,0.001f,0.001f,0f,1f}});

            imageAttr.SetColorMatrix(cm);

            g.DrawImage(picture, new Rectangle(0, 0, picture.Width, picture.Height), 0, 0, picture.Width, picture.Height, GraphicsUnit.Pixel, imageAttr);
            g.Dispose();
            imageAttr.Dispose();
            pictureBox1.Image = bmp;
            SaveAction(bmp);
        }
开发者ID:Strongelhold,项目名称:ImageProcessor,代码行数:25,代码来源:Form1.cs


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