Replace square pixel with round dot pixel

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I am attempting to do some image processing operations....what I want to do is take in a bitmap and replace the square pixel with a round dot pixel....I can iterate the bitmap and get the pixel color, brightness and replace them with another color...but would like to know how to change the shape of the pixel....

this is what I have so far:

 Bitmap testImg = (Bitmap)Image.FromFile(AppDomain.CurrentDomain.BaseDirectory +[URL="file://\\Assets\\Images\\Seps\\yellow_sep.png"]\\Assets\\Images\\Seps\\yellow_sep.png[/URL]);
            Bitmap result = new Bitmap(testImg.Width , testImg.Height);
            Graphics g = Graphics.FromImage(result);
            for (int i = 0; i < testImg.Width; i++)
            {
                for (int y = 0; y < testImg.Height; y++)
                {
                    Color c = testImg.GetPixel(i, y);
                    var brightness = Brightness(c);

                    if (c == Color.FromArgb((int)brightness, (int)brightness, (int)brightness, (int)brightness))
                    {
                       
                       
                        Pen dot = new Pen(Color.FromArgb((int)brightness, 0,0,0), 1F);
                        result.SetPixel(i, y, dot.Color);
                       
                        g = pictureBox2.CreateGraphics();
                        g.DrawEllipse(dot, i, y, 4, 4);
                        
                    }
                    else
                    {
                        Pen dot = new Pen(Color.FromArgb((int)brightness, 255,255,255), 1F);
                        result.SetPixel(i, y, dot.Color);
                        g = pictureBox2.CreateGraphics();
                        g.DrawEllipse(dot, i, y, 4, 4);
                        
                    }
                    
                }
            }

private float Brightness(Color c)
        {
            return (float)Math.Sqrt(
                c.R * c.R * .241 +
                c.G * c.G * .691 +
                c.B * c.B * .068);
        }

Any help would be appreciated

-InkedGFX
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,150
Location
Sydney, Australia
Programming Experience
10+
You can't change the shape of a pixel. A pixel is whatever shape the medium used to display the image decides it is. On a computer screen, that's generally going to be square while on a printer it may be round. The image itself doesn't contain any specific information about that.
 
Top Bottom