C# Graphics.DrawImage alters my colors

时间:2015-07-28 22:55:29

标签: c# .net system.drawing

I'm using Image Resizing to up and downscale icons but I'm noticing some color changes/alterations when I'm drawing it. The problem is not with the filters since I've checked the image output and it looks fine by itself.

Here's an example: left is how it should look like, right is what I see in my application. Color alteration

I've created a custom ToolStripItem and I'm drawing in its OnPaint function. The code I'm using for drawing looks like this.

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            e.Graphics.DrawImage(Image,
                new Rectangle(
                    new Point(Width / 2 - IconSize / 2, Height / 2 - IconSize / 2),
                    new Size(IconSize, IconSize)));

Update: I have set the PixelOffsetMode to Half and that fixes the cutout pixels you see in the above example but the colors are still off and it messes with the transparency. Left is the icon I have saved using its Save function and placed it on top of a screenshot of the icon that's being drawn with the above.

Also a note that this is using a different filter, hence why it doesn't like anything like the above.

enter image description here

0 个答案:

没有答案