How to make edges on a transparent image smooth

I have looked 'round the Internet and can't find an answer.  I have created a simple VS2012 project for illustration.

I have a circular bmp with white around the circle.

It looks like this after rendering; instructing the white to be transparent:

Windows 7 Start orb
Here is the code:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim bmp As Bitmap = New Bitmap(My.Resources.Windows_7_Start_Orb)
        PictureBox1.Image = bmp

        Dim g As Graphics = Graphics.FromImage(PictureBox1.Image)
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
    End Sub

Open in new window

How do I make the edges of the graphic smooth, and discard any unwanted white bits.  I've also tried this with PNG.

Who is Participating?
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
Basically you can't.  The problem you are seeing is that the light colored bits around the edge are technically not 'white' but usually a color in between the original white background and the color inside the image at that point.  I downloaded your image and those light colors are light blues and grays so they will not be converted to transparent by your code.

Images like that start out usually as much larger images with much higher resolution.  When they are saved in a reduced format, image software does 'anti-aliasing' which combines the background colors with the foreground colors in an attempt to make it look like it is higher resolution than it actually is.

Artifacts like those are why it is important when you creating images to take the background you want into consideration because once you reduce it and save it, you can't really take those artifacts out.

Now if you put that image on a white background in your project, those artifacts will work they way they did originally and effectively disappear.
GeoffHarperAuthor Commented:
I appreciate very much this concise explanation you have given as I was unable to find such a thing on the Internet.

Actually, I had figured all that out (I thought) but was hoping there was some sort of "magic" possible with the Graphics class.  ;)   It confirms what I thought.

Now I just have to figure out how to make my graphic with single-color smooth edges.


Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help, and thanks for the points.  Even in a good graphics editor, fixing that would be a manual process.  When you create your own graphics, you can avoid that by never combining the foreground with the back ground.  More common if you are going to use JPGs which have no transparency is to select the background to exactly match the back ground of the page that it is displayed.  For example, white background on a white page disappears.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.