Pirahnaplant
Well-known member
- Joined
- Mar 29, 2009
- Messages
- 75
- Programming Experience
- 3-5
How can I draw an image semi-transparent?
PictureBox1.Image = FadeBitmap(My.Resources.Pic1, 75)
Private Function FadeBitmap(ByVal bmp As Bitmap, ByVal OpacityPercent As Single) As Bitmap
Dim bmp2 As New Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb)
OpacityPercent = Math.Min(OpacityPercent, 100)
Using ia As New Imaging.ImageAttributes
Dim cm As New Imaging.ColorMatrix
cm.Matrix33 = OpacityPercent / 100.0F
ia.SetColorMatrix(cm)
Dim destpoints() As PointF = _
{New Point(0, 0), New Point(bmp.Width, 0), New Point(0, bmp.Height)}
Using g As Graphics = Graphics.FromImage(bmp2)
g.Clear(Color.Transparent)
g.DrawImage(bmp, destpoints, _
New RectangleF(Point.Empty, bmp.Size), GraphicsUnit.Pixel, ia)
End Using
End Using
Return bmp2
End Function