I’m in a situation where I need an image with a .Mask with a valid .Graphics, but I’m not understanding how pictures with masks work.
Without a mask, if I create a picture and draw a circle into it, I get what I expect: A black circle with a transparent background (light gray indicates transparent pixels):
Dim p As New Picture(100, 100)
Dim gg As Graphics = p.Graphics
gg.FillOval(0, 0, 100, 100)
g.DrawPicture(p, 0, 0)
But if I explicitly create a picture with 32 bits (the above image is also 32 bits, but this will create an image with a .Mask property. But the default state of the image has a white (opaque) background:
Dim p As New Picture(100, 100, 32)
Dim gg As Graphics = p.Graphics
gg.FillOval(0, 0, 100, 100)
g.DrawPicture(p, 0, 0)
So, how do I clear the background and draw my opaque circle? Clearing the mask removes the white background, but drawing into the picture’s graphics doesn’t affect the alpha channel? Is this the expected behavior?
Dim p As New Picture(100, 100, 32) // (updated post to fix missing bit depth parameter)
Dim gg As Graphics = p.Graphics
Dim mg As Graphics = p.mask.Graphics
mg.ClearRectangle(0, 0, p.Width, p.Height)
gg.FillOval(0, 0, 100, 100)
g.DrawPicture(p, 0, 0)
I’m in a situation where I need to draw—as quickly as possilble–into the alpha channel of a picture. I’m aware of the ApplyMask method, but I don’t want to do a lot of copying of pixel data. I’d like to issue a few drawing commands that would only affect the alpha, like this text example, where I’ve written text in the alpha channel and it erases the circle:
(This is just a simplified illustration)