C# image drawing colours are incorrect
- by Jon Tackabury
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;
}