Reputation: 97
I am working with Microsoft Visual Basic 2010 Express and I have ran into an issue with transparent images and picture boxes. When I set the size mode to StretchImage it seems to add a white border around my images. If I leave it set to Normal it displays properly with no added border.
In this picture you can see what I am talking about. The left side is how it's suppose to look. The right side is what happens when I resize the picturebox.
Here is the image I am using
For my program I need to scale these images based on the size input by the user. The input size will never exceed 100x100px. The images are transparent .gif's that are 160x160px and stored in the program resources. These images will only be displayed on screen and never output by the program. I was wondering if there is anyway to scale transparent images without getting a white border around them.
Upvotes: 0
Views: 1679
Reputation: 38077
Try manually drawing the image and setting the interpolation mode. You may need to play with different values to get the look you want:
Dim destination = New Bitmap(100, 100)
Dim original = Image.FromFile("gear-256.gif")
Using g = Graphics.FromImage(destination)
g.InterpolationMode = InterpolationMode.HighQualityBilinear
g.DrawImage(original, New Rectangle(0, 0, destination.Width, destination.Height), New Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel)
End Using
PictureBox1.Image = destination
Upvotes: 1