I need to make the white of a picture transparent. I know I can do that with mask, but I have trouble understanding how it works. The example in the LR shows how to create a mask, but not how to use it to make a particular color transparent.
dim p As new Picture(100, 100, 32)
p.Graphics.ForeColor = &cFFFFFF
p.Graphics.FillRect(0, 0, 100, 100)
p.Graphics.ForeColor = &c00FF00
p.Graphics.FillOval(0, 0, 100, 100)
you can make white transparent with
p.Transparent = 1
It’s odd, the property is an integer instead of boolean. 0=off, 1=on, 2=?.
Another way, or if the Picture has an alpha channel, you can build the Mask/Alpha manually and then apply it.
[code] //given p
dim p2 As new Picture(100, 100) //new picture to build mask/alpha into
dim surf As RGBSurface = p.RGBSurface
dim surf2 As RGBSurface = p2.RGBSurface
dim x, y As integer
for y = 0 to 99
for x = 0 to 99
if surf.Pixel(x, y) = &cFFFFFF then //if pixel is target color
surf2.Pixel(x, y) = &cFFFFFF //set transparent
else
surf2.Pixel(x, y) = &c000000 //set opaque
end
next
next
p.ApplyMask(p2) //apply mask/alpha to original[/code]
[quote=131401:@Will Shank]If you have a masked picture like this
dim p As new Picture(100, 100, 32)
p.Graphics.ForeColor = &cFFFFFF
p.Graphics.FillRect(0, 0, 100, 100)
p.Graphics.ForeColor = &c00FF00
p.Graphics.FillOval(0, 0, 100, 100)
you can make white transparent with