I'm having trouble reading the pixel values ββfrom the bitmap that I am generating. First I create a bitmap named maskBitmap in my class using this code:
void generateMaskBitmap() { if (inputBitmap != null) { Bitmap tempBitmap = new Bitmap(inputBitmap.Width, inputBitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(tempBitmap)) { Brush brush = Brushes.Black; for (int y = 0; y < tempBitmap.Height; y += circleSpacing) { for (int x = 0; x < tempBitmap.Width; x += circleSpacing) { g.FillEllipse(brush, x, y, circleDiameter, circleDiameter); } } g.Flush(); } maskBitmap = (Bitmap)tempBitmap.Clone(); } }
Then I will try to apply the mask to the source image using the following code:
void generateOutputBitmap() { if (inputBitmap != null && maskBitmap != null) { Bitmap tempBitmap = new Bitmap(inputBitmap.Width, inputBitmap.Height); for (int y = 0; y < tempBitmap.Height; y++) { for (int x = 0; x < tempBitmap.Width; x++) { Color tempColor = maskBitmap.GetPixel(x, y); if (tempColor == Color.Black) { tempBitmap.SetPixel(x, y, inputBitmap.GetPixel(x, y)); } else { tempBitmap.SetPixel(x, y, Color.White); } } } outputBitmap = tempBitmap; } }
The bitmap image of the mask is successfully generated and displayed in the image window, however, the color values ββfor each pixel when testing with " tempColor " are displayed empty (A = 0, R = 0, G = 0, B = 0). I know performance issues with getpixel / setpixel, but this is not a problem for this project. I also know that "tempColor == Color.Black" not a valid test, but this is just the place for my comparison code.
source share