Invalid C # Image Image Colors

I have an original bitmap that is 1x1, and I'm trying to take this image and draw it in a new bitmap. The source bitmap is red, but for some reason, the new bitmap ends with a gradient (see Image). Using the code below, shouldn't the new bitmap be completely red? Where does he get white / alpha from?

alt text http://www.binaryfortress.com/Temp/Error.jpg

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; } 
+4
source share
2 answers

This is not a good way to fill the area with color. A better approach would be to determine the color of the pixel in the original image and use that color to fill the target.

 Bitmap source = // get the source Color color = source.GetPixel(1, 1); Bitmap target = // get the target target.Clear(color); 

However, the problem is most likely InterpolationMode , as it is used when scaling images. Try using Low istead HighQualityBicubic .

 g.InterpolationMode = InterpolationMode.Low; 
+7
source

I found this solution for your problem:

 g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; 
0
source

All Articles