I'm just starting out with VB.net after many years of VB 6.0 and I thought I'd get started with some graphics.
Just for fun I'm using BitBlt to draw a bitmap I have loaded as a resource and draw it on a form. I can load an existing image from a picturebox and bitblt it, which works fine. I can also load the bitmap from resources and store it into the picturebox, but when I take the bitmap, turn it into a GDI Graphics object and BitBlt it onto the form, all I get is a black square that is the same size as the bitmap.
Here is my code:
Dim srcBmp As New Bitmap(Me.GetType, "colorwheel.bmp")
Dim drect As New Rectangle(0, 0, 233, 233)
'srcGrp = PictureBox1.CreateGraphics 'This works.
srcGrp = Graphics.FromImage(srcBmp) 'This doesn't
targetGrp = Me.CreateGraphics 'destination graphics
srcHdc = srcGrp.GetHdc
TargetHdc = targetGrp.GetHdc
BitBlt(TargetHdc, 0, 0, 233, 233, srcHdc, 0, 0, SRCCOPY)
srcGrp.ReleaseHdc(srcHdc)
targetGrp.ReleaseHdc(TargetHdc)
targetGrp.Dispose()
srcBmp.Dispose()
srcGrp.Dispose()
The reasons I want to use bitblt are a) I've used it before, so it was my first choice. b) I know that it is possible to use a black and white mask to mask out some areas as transparent, which is what I need. and b) the graphics may be moving around frequently.
Is there a better way of drawing graphics with a transparent background onto a form or picturebox? e.g. a png with an alpha channel?