?
Solved

How to make edges on a transparent image smooth

Posted on 2013-06-28
3
Medium Priority
?
512 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Progress
Introduction to Processes

764 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