1

Maybe someone out there can help, I am trying to display a transparent PNG in a form as a splash screen. The code on the form is:

Sub Form_Paint(ByVal s As Object, ByVal e As PaintEventArgs) Handles Me.Paint
  Dim r As New Rectangle(0, 0, 728, 462)
  Dim newBitmap As Bitmap
  newBitmap = Bitmap.FromFile("Logo.png")
  e.Graphics.DrawImage(newBitmap, r)
end sub

The resulting image shows with an ugly 'feathered' border. See here:
enter image description here

The image is a 32bit ARGB that has been given transparency on the edges. This is the PNG embedded in a web page:

enter image description here

Does anyone know how to get rid of the border?

1 Answers1

0

Try this:

e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

See also this: How to draw smooth images with C#?

Anyway, as another user noted, the issue is with the image which was created without any anti-aliasing. The above snippet will alleviate the problem but the best option is to adjust the image.

Regards

Community
  • 1
  • 1
Dan
  • 1,060
  • 13
  • 39
  • Thanks for the suggestion but I don't think it's the image, see my edit above for how it looks when embedded in a web page. Also the snippet made no difference. – John Robota Aug 07 '13 at 23:00
  • I've been checking MSDN and the problem lies in the Image Class (base class of Bitmap). I found here [link](http://msdn.microsoft.com/en-us/library/4sahykhd.aspx) the following: The Image class does not support alpha transparency in bitmaps. To enable alpha transparency, use PNG images with 32 bits per pixel. – Dan Aug 08 '13 at 08:54
  • Can you debug bmp.PixelFormat? – Dan Aug 08 '13 at 08:56
  • I tried SetStyle(ControlStyles.SupportsTransparentBackColor, True), then making the background transparent but it just shows the background as solid beige. I can get rid of that beige by making the transparency key to be "systemcolors.control" but it still has the border. – John Robota Aug 09 '13 at 00:07
  • Thanks for your help dna2, but I am cutting my losses. Just going to put a background in the image, get rid of all the transparent parts. – John Robota Aug 09 '13 at 00:11