0

I need to fill some white pixels in my selFrame image from the bmpOut image. Now, If pixel3 is transparent or empty, it will check all sides of it. If a pixel which is not transparent nor empty is around the pixel, pixel3 will get it's value from pixel2. How can I check if the pixels around pixel3 is transparent or not? Gap of the pixel is max at 10. Here's what I got so far

for (int c = 0; c < selFrame.Width; c++)
 for (int j = 0; j < selFrame.Height; j++)
   {
     var pixel2 = bmpOut.GetPixel(c, j);
     var pixel3 = selFrame.GetPixel(c, j);
     if (pixel3.ToArgb() == System.Drawing.Color.Transparent.ToArgb() || pixel3.IsEmpty)
       {

         // do process here
        }

    }

Updated code

 for (int c = 0; c < selFrame.Width; c++)
            for (int j = 0; j < selFrame.Height; j++)
            {
                var pixel2 = bmpOut.GetPixel(c, j);
                var pixel3 = selFrame.GetPixel(c, j);
                if (pixel3.ToArgb() == System.Drawing.Color.White.ToArgb() || pixel3.IsEmpty)
                {
                    for (int n = 1; n < 20; n++)
                    {
                        if (c + n < selFrame.Width && j + n < selFrame.Height)
                            if (c - n > 0 && j - n > 0)
                            {
                                var pix = selFrame.GetPixel(c + n, j + n);
                                var pix2 = selFrame.GetPixel(c - n, j - n);
                                if (pix.ToArgb() != System.Drawing.Color.Transparent.ToArgb() || !pix.IsEmpty)
                                    if (pix2.ToArgb() != System.Drawing.Color.Transparent.ToArgb() || !pix2.IsEmpty)
                                    {
                                        selFrame.SetPixel(c, j,pixel2);
                                        MessageBox.Show("q");
                                    }

                        }

                    }
                }

            }

The messagebox is showing, but it is not filling up the white pixels

Untitled
  • 115
  • 2
  • 13
  • I think.. your question is how to access neighbors of pixel. Is it right? – se0kjun May 04 '16 at 00:01
  • Yes, the fastest way possible. And checking if its transparent or not – Untitled May 04 '16 at 00:07
  • You can use for-loop notation of `smoothing filter`. So refer to http://stackoverflow.com/questions/12973255/algorithm-for-smoothing – se0kjun May 04 '16 at 00:16
  • For anything fast you need to use `LockBits`. See [here (question plus answer))](http://stackoverflow.com/questions/25976620/how-can-i-color-pixels-that-are-not-black-in-bitmap-in-yellow-using-lockbits/25977692?s=1|3.3054#25977692) for an example. I doubt that checking for Empty is necessary as you are not creating a structure but pulling the color from a bitmap. - Simply checking for transparency is: `color1.A == 0` But anything with a lot of getpixel/setpixel will be slow. – TaW May 04 '16 at 08:00

0 Answers0