C# image drawing colours are incorrect
Posted
by Jon Tackabury
on Stack Overflow
See other posts from Stack Overflow
or by Jon Tackabury
Published on 2009-12-07T15:20:14Z
Indexed on
2010/05/11
5:44 UTC
Read the original article
Hit count: 229
I have a source bitmap that is 1x1 and I am trying to take that image and draw it to a new bitmap. The source bitmap is all red, but for some reason the new bitmap ends up with a gradient (see image). Using the code below, shouldn't the new bitmap be completely red? Where is it getting the white/alpha from?
private void DrawImage()
{
Bitmap bmpSOURCE = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bmpSOURCE))
{
g.Clear(Color.Red);
}
Bitmap bmpTest = new Bitmap(300, 100, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bmpTest))
{
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.AssumeLinear;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PageUnit = GraphicsUnit.Pixel;
g.PixelOffsetMode = PixelOffsetMode.None;
g.SmoothingMode = SmoothingMode.None;
Rectangle rectDest = new Rectangle(0, 0, bmpTest.Width, bmpTest.Height);
Rectangle rectSource = new Rectangle(0, 0, 1, 1);
g.DrawImage(bmpSOURCE, rectDest, rectSource, GraphicsUnit.Pixel);
}
pictureBox1.Image = bmpTest;
}
© Stack Overflow or respective owner