Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim graphicsObject As Graphics
graphicsObject = Me.CreateGraphics()
Dim myBitmap = New Bitmap("D:\Downloads\demo.png") ' my source is a simple green box drawn on a red background
' Draw myBitmap to the screen.
graphicsObject.DrawImage(myBitmap, 0, 0, myBitmap.Width, myBitmap.Height)
' Make red transparent
Dim BackColor As Color
BackColor = Color.FromArgb(255, 0, 0)
myBitmap.MakeTransparent(BackColor) ' and you can add additional transparent colours if you want.
' Draw the bitmasked bitmap to the form.
graphicsObject.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, myBitmap.Height)
' Simple Alpha masking
Dim rc As New Rectangle(0, myBitmap.Height, myBitmap.Width, myBitmap.Height)
Dim cm As New ColorMatrix()
Dim ia As New ImageAttributes()
myBitmap = New Bitmap("D:\Downloads\demo.png") ' just original bitmap again since MakeTransparent modifies the in memory bitmap
cm.Matrix33 = 0.5 ' set our alpha to 50%
ia.SetColorMatrix(cm)
graphicsObject.DrawImage(myBitmap, rc, 0, 0, myBitmap.Width, myBitmap.Height, GraphicsUnit.Pixel, ia) ' use slightly different DrawImage in order to use alpha
End Sub
End Class