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


C# Imaging.ImageAttributes类代码示例

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


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

示例1: Apply

        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:29,代码来源:GrayscaleFilter.cs

示例2: AudioChanged

        // Callback from VolumeDetector
        public void AudioChanged(DeviceInfo info)
        {
            // Windows7 sometimes triggers callback when volume hasn't changed.
            if (lastInfo != null)
            {
                if (info.Muted == lastInfo.Muted && info.Volume == lastInfo.Volume )
                    return;
            }
            lastInfo = info;

            try
            {
                this.Opacity = settings.Opacity + _Opacity;
                if (this.Visible == false)
                    this.Visible = true; // throw in preview

                // Manually draw the image to get the transparency
                string image = ResolveImage(info, settings, BasePath);
                System.Drawing.Image actualImage = System.Drawing.Image.FromFile(image);
                ImageAttributes attr = new ImageAttributes();
                Rectangle dstRect = new Rectangle(0, 0, actualImage.Width, actualImage.Height);
                CreateGraphics().DrawImage(actualImage, dstRect, 0, 0, actualImage.Width, actualImage.Height,
                    GraphicsUnit.Pixel, attr);

                System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(WaitAndHide));
                lastMove = System.DateTime.Now;
                t.Start();
            }
            catch (ObjectDisposedException)
            {
                // In preview we recieved a callback from an item that we cannot
                // access
                return;
            }
        }
开发者ID:kenmazaika,项目名称:volumedisplay,代码行数:36,代码来源:frmDisplay.cs

示例3: MakeGrayscaleWithColorMatrix

 private Bitmap MakeGrayscaleWithColorMatrix(Bitmap original)
 {
     //create a blank bitmap the same size as original
     Bitmap newBitmap = new Bitmap(original.Width, original.Height);
     //get a graphics object from the new image
     Graphics g = Graphics.FromImage(newBitmap);
     //create the grayscale ColorMatrix
     ColorMatrix colorMatrix = new ColorMatrix(
        new float[][]
       {
          new float[] {.3f, .3f, .3f, 0, 0},
          new float[] {.59f, .59f, .59f, 0, 0},
          new float[] {.11f, .11f, .11f, 0, 0},
          new float[] {0, 0, 0, 1, 0},
          new float[] {0, 0, 0, 0, 1}
       });
     //create some image attributes
     ImageAttributes attributes = new ImageAttributes();
     //set the color matrix attribute
     attributes.SetColorMatrix(colorMatrix);
     //draw the original image on the new image
     //using the grayscale color matrix
     g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
        0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
     //dispose the Graphics object
     g.Dispose();
     return newBitmap;
 }
开发者ID:bhabesh7,项目名称:bhabeshgitprojects,代码行数:28,代码来源:ImageViewModel.cs

示例4: AsGrayScaleImage

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     A Bitmap extension method that converts a bitmap to a gray scale image.
        /// </summary>
        /// <remarks>   Aaevans, 2/16/2016. </remarks>
        /// <param name="bitmap">   The bitmap to act on. </param>
        /// <returns>   A Bitmap. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public static Bitmap AsGrayScaleImage(this Bitmap bitmap)
        {
            var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);

            using (var g = Graphics.FromImage(newBitmap))
            {
                var colorMatrix =
                    new ColorMatrix(
                        new[]
                            {
                                new[] { .3f, .3f, .3f, 0, 0 },
                                new[] { .59f, .59f, .59f, 0, 0 },
                                new[] { .11f, .11f, .11f, 0, 0 },
                                new float[] { 0, 0, 0, 1, 0 },
                                new float[] { 0, 0, 0, 0, 1 }
                            });

                var attributes = new ImageAttributes();
                attributes.SetColorMatrix(colorMatrix);
                g.DrawImage(
                    bitmap,
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    0,
                    0,
                    bitmap.Width,
                    bitmap.Height,
                    GraphicsUnit.Pixel,
                    attributes);
            }

            return newBitmap;
        }
开发者ID:WillCode4Cash,项目名称:Dynyx,代码行数:40,代码来源:ImageExtensions.cs

示例5: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            begin = DateTime.Now.Ticks;
            
            Bitmap currentBitmap = new Bitmap(pictureBox1.Image);
            Graphics g = Graphics.FromImage(currentBitmap);

            ImageAttributes ia = new ImageAttributes();

            float[][] colorMatrix =   {
                new float[] {0.299f,   0.299f,   0.299f,   0,   0},
                new float[]   {0.587f,   0.587f,   0.587f,   0,   0},
                new float[]   {0.114f,   0.114f,   0.114f,   0,   0},
                new float[]   {0,   0,   0,   1,   0},
                new float[]   {0,   0,   0,   0,   1}
                                      };

            ColorMatrix cm = new ColorMatrix(colorMatrix);

            ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            g.DrawImage(currentBitmap, new Rectangle(0, 0, currentBitmap.Width, currentBitmap.Height), 0, 0, currentBitmap.Width, currentBitmap.Height, GraphicsUnit.Pixel, ia);

            pictureBox1.Image = currentBitmap;

            g.Dispose();
            end = DateTime.Now.Ticks;
            label1.Text = (end - begin) / 1000 + "毫秒";
        }
开发者ID:MaisonWan,项目名称:PhotoHuntHelper,代码行数:29,代码来源:FormTest.cs

示例6: 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

示例7: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            if (IsMouseOver && Enabled)
            {
                using (Pen pen = new Pen(ForeColor))
                {
                    e.Graphics.DrawRectangle(pen, Rectangle.Inflate(ClientRectangle, -1, -1));
                }
            }

            using (ImageAttributes imageAttributes = new ImageAttributes())
            {
                ColorMap[] colorMap = new ColorMap[2];
                colorMap[0] = new ColorMap();
                colorMap[0].OldColor = Color.FromArgb(0, 0, 0);
                colorMap[0].NewColor = ForeColor;
                colorMap[1] = new ColorMap();
                colorMap[1].OldColor = Image.GetPixel(0, 0);
                colorMap[1].NewColor = Color.Transparent;

                imageAttributes.SetRemapTable(colorMap);

                e.Graphics.DrawImage(
                   Image,
                   new Rectangle(0, 0, Image.Width, Image.Height),
                   0, 0,
                   Image.Width,
                   Image.Height,
                   GraphicsUnit.Pixel,
                   imageAttributes);
            }

            base.OnPaint(e);
        }
开发者ID:675492062,项目名称:behaviac,代码行数:34,代码来源:InertButtonBase.cs

示例8: ResizeImage

        public static Bitmap ResizeImage(Image image, int width, int height)
        {
            var destRect = new Rectangle(0, 0, width, height);
            var destImage = new Bitmap(width, height);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                    graphics.Dispose();
                }
            }

            return destImage;
        }
开发者ID:anhnnp,项目名称:Nhakhoaso,代码行数:25,代码来源:UtilImage.cs

示例9: TransformImage

        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="source">The current image to process</param>
        /// <param name="destination">The new Image to return</param>
        /// <returns>
        /// The processed <see cref="System.Drawing.Bitmap"/>.
        /// </returns>
        public override Bitmap TransformImage(Image source, Image destination)
        {
            using (Graphics graphics = Graphics.FromImage(destination))
            {
                using (ImageAttributes attributes = new ImageAttributes())
                {
                    attributes.SetColorMatrix(this.Matrix);

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

                    graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
                }
            }

            // Fade the contrast
            destination = Adjustments.Contrast(destination, -25);

            // Add a glow to the image.
            destination = Effects.Glow(destination, Color.FromArgb(70, 255, 153, 102));

            // Add a vignette to finish the effect.
            destination = Effects.Vignette(destination, Color.FromArgb(220, 102, 34, 0));

            return (Bitmap)destination;
        }
开发者ID:AlexSkarbo,项目名称:ImageProcessor,代码行数:33,代码来源:PolaroidMatrixFilter.cs

示例10: TransformImage

        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="factory">
        /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
        /// the image to process.
        /// </param>
        /// <param name="image">The current image to process</param>
        /// <param name="newImage">The new Image to return</param>
        /// <returns>
        /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public Image TransformImage(ImageFactory factory, Image image, Image newImage)
        {
            using (Graphics graphics = Graphics.FromImage(newImage))
            {
                using (ImageAttributes attributes = new ImageAttributes())
                {
                    attributes.SetColorMatrix(this.Matrix);

                    Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);

                    graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
                }
            }

            // Add a vignette to finish the effect.
            factory.Update(newImage);
            Vignette vignette = new Vignette();
            newImage = (Bitmap)vignette.ProcessImage(factory);

            // Reassign the image.
            image.Dispose();
            image = newImage;

            return image;
        }
开发者ID:nacholemmo,项目名称:ImageProcessor,代码行数:37,代码来源:LomographMatrixFilter.cs

示例11: CMVPlayer

        public CMVPlayer()
        {
            InitializeComponent();

            // Paint values
            drawArea = new Rectangle(0, 0, Width, Height);

            // Draw stage constants
            magenta = Color.FromArgb(255, 255, 0, 255);

            attributes = new ImageAttributes();

            playTimer = new Timer();
            playTimer.Interval = 1000 / 25;
            playTimer.Tick += new EventHandler(timerTick);

            DoubleBuffered = true;

            Reset();

            cmv = new CMV();
            tileset = new TileSet();

            renderedTiles = new Dictionary<short, Bitmap>();
            forceRedraw = true;
        }
开发者ID:billylegota,项目名称:CMV-Editor,代码行数:26,代码来源:CMVPlayer.cs

示例12: AlphaBlend

        public static Graphics AlphaBlend(this Graphics gr, Bitmap b, Rectangle to, Rectangle from, float opacity)
        {
            #if WINCE
            byte bopacity = unchecked((byte)(255 * opacity));

            using (Graphics gxSrc = Graphics.FromImage(b))
            {
              IntPtr hdcDst = gr.GetHdc();
              IntPtr hdcSrc = gxSrc.GetHdc();
              BlendFunction blendFunction = new BlendFunction();
              blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER;
              blendFunction.BlendFlags = (byte)BlendFlags.Zero;
              blendFunction.SourceConstantAlpha = bopacity;
              blendFunction.AlphaFormat = (byte)0;
              try{
                  PlatformAPI.AlphaBlend(hdcDst, to.X, to.Y, to.Width, to.Height, hdcSrc, from.X, from.Y, from.Width, from.Height, blendFunction);
              }catch(Exception e){}
              gr.ReleaseHdc(hdcDst);
              gxSrc.ReleaseHdc(hdcSrc);
            }
            #else
            var ia = new ImageAttributes();
            float[][] ptsArray = {
                        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, opacity, 0},
                        new float[] {0, 0, 0, 0, 1}};
            ia.SetColorMatrix(new ColorMatrix(ptsArray));
            gr.DrawImage(b, to, from.X, from.Y, from.Width, from.Height, GraphicsUnit.Pixel, ia);
            #endif
            return gr;
        }
开发者ID:hksonngan,项目名称:fleux,代码行数:33,代码来源:GraphicsExtensions.cs

示例13: ExecuteFilter

        /// <summary>
        /// Executes this filter on the input image and returns the result
        /// </summary>
        /// <param name="inputImage">input image</param>
        /// <returns>transformed image</returns>
        public override Image ExecuteFilter(Image inputImage)
        {
            ///Reference from http://www.bobpowell.net/grayscale.htm
              Bitmap bm = new Bitmap(inputImage.Width, inputImage.Height);
              Graphics g = Graphics.FromImage(bm);
              ColorMatrix cm;

              if (_isBright)
              {
            cm = new ColorMatrix(new float[][]{   new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0,0,0,1,0,0},
                                  new float[]{0,0,0,0,1,0},
                                  new float[]{0,0,0,0,0,1}});
              }
              else
              {

            //Gilles Khouzams colour corrected grayscale shear
            cm = new ColorMatrix(new float[][]{   new float[]{0.3f,0.3f,0.3f,0,0},
                                new float[]{0.59f,0.59f,0.59f,0,0},
                                new float[]{0.11f,0.11f,0.11f,0,0},
                                new float[]{0,0,0,1,0,0},
                                new float[]{0,0,0,0,1,0},
                                new float[]{0,0,0,0,0,1}});
              }

              ImageAttributes ia = new ImageAttributes();
              ia.SetColorMatrix(cm);
              g.DrawImage(inputImage, new Rectangle(0, 0, inputImage.Width, inputImage.Height), 0, 0, inputImage.Width, inputImage.Height, GraphicsUnit.Pixel, ia);
              g.Dispose();
              return bm;
        }
开发者ID:Epitomy,项目名称:CMS,代码行数:39,代码来源:BlackAndWhite.cs

示例14: GetGhostBitmap

 public static Bitmap GetGhostBitmap(string name)
 {
     float[][] newColorMatrix = new float[5][];
     float[] numArray2 = new float[5];
     numArray2[0] = 1f;
     newColorMatrix[0] = numArray2;
     numArray2 = new float[5];
     numArray2[1] = 1f;
     newColorMatrix[1] = numArray2;
     numArray2 = new float[5];
     numArray2[2] = 1f;
     newColorMatrix[2] = numArray2;
     numArray2 = new float[5];
     numArray2[3] = 0.5f;
     newColorMatrix[3] = numArray2;
     numArray2 = new float[5];
     numArray2[4] = 1f;
     newColorMatrix[4] = numArray2;
     ColorMatrix matrix = new ColorMatrix(newColorMatrix);
     ImageAttributes imageAttr = new ImageAttributes();
     imageAttr.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
     Bitmap image = GetBitmap(name);
     Bitmap bitmap2 = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);
     using (Graphics graphics = Graphics.FromImage(bitmap2))
     {
         graphics.FillRectangle(SystemBrushes.Window, new Rectangle(0, 0, image.Width, image.Height));
         graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
     }
     return bitmap2;
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:30,代码来源:IconService.cs

示例15: grayScale

        // Obraz w skali szarości;
        internal void grayScale(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            //Srednia skladowych       // Wykorzystanie modelu YUV
            const float rMod = 0.333f; //rMod = 0.299f;
            const float gMod = 0.333f; //gMod = 0.587f;
            const float bMod = 0.333f; //bMod = 0.114f;
            Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] {rMod, rMod, rMod, 0, 1},
                new[] {gMod, gMod, gMod, 0, 1},
                new[] {bMod, bMod, bMod, 0, 1},
                new[] {0.0f, 0.0f, 0.0f, 1, 1},
                new[] {0.0f, 0.0f, 0.0f, 0, 1}
            });

            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;
            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            //myBitmap.updateArrays();
            g.Dispose();
        }
开发者ID:radol91,项目名称:BitMapEditorSolution,代码行数:27,代码来源:MyBitmapEditor.cs


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