Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15429

Trying to make bitmap with a transparent background.

$
0
0
Hi,

I'm failing to make bitmap with a transparent background. (Yes, that might be a bit of an impossibility)

I'm making a cursor from an image within a picturebox, The cursor is made but I can't make it's background transparent which makes a pretty poor cursor.

I discovered early-on that 'TransparentKey' only seems to work with a whole Form, not individual controls.
I've saved the image that I've made from the picturebox image, tried to save it as a .png but when opened in PaintShop Pro the background is not transparent.

In the following code, I've retained all my attempts so that you can see what I've tried, but the codes which don't work are just remarked-out. (Line 6 also shows the Intellisence error notification.)

vb.net Code:
  1. Private Sub MakeCursor()
  2.         'PictureBox1.BackColor = Color.Transparent
  3.         'PictureBox1.Refresh()
  4.         CaptureImage(PictureBox1)
  5.         Cur = New Bitmap(map)
  6.         'Cur.BackColor = Color.Transparent !!  BackColor is not a member of Bitmap.
  7.         Dim ptrCur As IntPtr = Cur.GetHicon
  8.         Csr = New Cursor(ptrCur)
  9.         Me.Cursor = Csr
  10.         map.Dispose()
  11.     End Sub
  12.  
  13.     Private Sub CaptureImage(ctrl As Control)
  14.         With ctrl
  15.             map = New Bitmap(.Width, .Height)
  16.             'This next line doesn't fail, but doesn't seem to work either. :o(
  17.             .BackColor = Color.Transparent
  18.             .DrawToBitmap(map, .ClientRectangle)
  19.         End With
  20.  
  21.         '   Temp.
  22.         map.Save("C:\Temp\ImageTrial.png", ImageFormat.Png)
  23.  
  24.     End Sub


Poppa

Viewing all articles
Browse latest Browse all 15429

Latest Images

Trending Articles



Latest Images