How do i create a mask(see post for details)?

Apr 22 2005 1:57 PM
I need help with this one.... I want to use a mask on an image.A mask is a greyscale bitmap of the image.Black represents transparent regions and white opaque regions.The image can contain grey tones: the darker a color is the more transparent the pixel is.Same for whiter colors: the whiter the color the more opaque the pixel.(too bad i can't attach an image).After I overlay the image and the mask I should obtain whatever is in the white area;the rest should be transparent.Also the the grey colors should semi-transparent. Now,how can I do this? I've tried the slowest method(well at least that's what I think): to get the color of each pixel of the mask image and see if it's black.If so,set the same pixel in the main image to Transparent.But it doesn't work.Instead of a transparent color I get white.Here's the code: Dim bmpMask As New Bitmap("c:\mask.bmp") Dim bmpImg As New Bitmap("c:\img.bmp") Dim i, j As Integer For i = 0 To bmpMask.Width - 1 For j = 0 To bmpMask.Height - 1 If bmpMask.GetPixel(i, j).ToArgb = System.Drawing.Color.Black.ToArgb Then bmpImg.SetPixel(i, j, System.Drawing.Color.Transparent) End If Next Next 'Draw the image on the form Dim g As Graphics = Me.CreateGraphics g.DrawImage(bmpImg, 10, 10) But I don't want to use this method(if it will ever work :D ).It's slow(not to mention if I have big and many images) and it doesn't work for semi-transparent colors. Is there another method?