Solved

How to make edges on a transparent image smooth

Posted on 2013-06-28
3
509 Views
Last Modified: 2013-06-29
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)
        bmp.MakeTransparent(Color.White)
        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.

Thanks!
-Geoff
0
Comment
Question by:GeoffHarper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39286109
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.
0
 
LVL 4

Author Closing Comment

by:GeoffHarper
ID: 39286551
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.

Thanks!

-Geoff
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39286953
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question