Question Visual Basic 2008 Setting image background color

mray190

New member
Joined
Dec 16, 2011
Messages
1
Programming Experience
1-3
I am doing a project for my Computer Science class and need help on how to make a picture have a transparent background. As of right now, I am having the picture be stored as a Bitmap and setting the white color attribute of the bitmap to transparent; then drawing the bitmap. It works and creates the white on the bitmap to transparent, but I am still lost on how to move the bitmap around on the screen. I am creating an angry birds remake and want the bird to fly across the screen, but first need the background white on the bird to be transparent. How can I save the bitmap with transparent background to a picture box so i can move it around?

here is my code so far:

Imports System.Drawing.Imaging
Public Class Form1


Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim picBird As Bitmap = My.Resources.Bird
'Sets the image of the bitmap picBird as the picture Bird in my resources
Dim attr As New ImageAttributes
attr.SetColorKey(Color.White, Color.White)
'Sets an image attribute to the color range white to white (or only white)
Dim dstRect As New Rectangle(0, 0, picBird.Width, picBird.Height)
e.Graphics.DrawImage(picBird, dstRect, 0, 0, picBird.Width, picBird.Height, GraphicsUnit.Pixel, attr)


End Sub


End Class

Please help. Thanks!
 
Top Bottom