[Closed] Can an alpha channel from one bitmap be copied to another bitmap?
Seems like this should be possible AND simple, but I can’t figure it out. Is it possible to assign the alpha channel from one bitmap to another? For instance, if I create a new red bitmap using bitmap 16 16 color:(color 255 0 0), is it possible to load a .tif from the hard-drive and use it’s alpha channel to give this new map transparency?
Thanks!
Off the top of my head, I’m guessing you could create a new bitmap, open a file with a valid alpha channel, and then use some combination of getPixels and setPixels to combine the colors from one source with the alpha from the second source.
Remember that the color value has a fourth “optional” value that defines the alpha channel.
There might be a better way to go about this… let me know how it goes…
Thanks, Marco
Yeah, you’re right, that using getPixels and setPixels along with the alpha paramameter for each color object definately worked… I was just hoping that there was something that ran quicker like the pasteBitmap function.
Thanks again!
you could try something like this…
[ol]
[li]Create a Mask map ( myMask = mask() )[list=1][/li][li]Place your RGB bitmap in the Map slot ( myRGB = myMask.map = Bitmap filename:“rgb.tga” )[list=1][/li][li]Disable filtering on this Bitmap ( myRGB.filtering = 2 )[/li][/ol]
[li]Place your Alpha bitmap in the Mask slot ( myAlpha = myMask.mask = Bitmap filename:“alpha.tga” )[/li]
[ol]
[li]If different in resolution from the RGB bitmap, disable filtering on this Bitmap as well (presumably you’d want it filtered, at least, better to scale to size in something other than Max, though, and then definitely disable filtering)[/li][li]Set the Mono Channel Output mode to Alpha ( myAlpha.monoOutput = 1 )[/li][/ol]
[/list]
[li]Create a bitmap with the resolution desired ( myRGBwithAlpha = bitmap width height )[/li][li]Rendermap() the result Mask map into that bitmap ( rendermap myMask into:myRGBwithAlpha )[/li][/list]If you don’t have your RGB and Alpha bitmaps saved, and instead just have them in-memory (created via render(), setpixel bits, etc.), you can specify a dummy bitmap file for the Bitmap texture map, and then copy your in-memory bitmaps to the map’s .bitmap property.
Whether or not this is faster than getPixels/setPixels depends a bit on the size of the bitmaps… it’s certainly still not optimal.
You could also, maybe, try something with .NET.
Playing around some with pasteBitmap itself, it seems like things should have worked with blend mode and an alphaMultiplier of 0.0, but it leaves artifact in the alpha channel if both bitmaps have alpha channels. If your RGB bitmap doesn’t have an alpha channel, you might be okay with pasteBitmap?
Edit: e.g.
a_ = rgbBitmap
b_ = alphaBitmap
-- clear out the RGB bitmap's alpha
for y = 0 to (a_.height - 1) do (
scanline = getPixels a_ [0,y] a_.width
for x = 1 to scanline.count do (
scanline[x].a = 0.0
)
setPixels a_ [0,y] scanline
)
-- now paste B on top with a blend, but let it think its alpha is zero so no RGB is composited
pasteBitmap b_ a_ [0,0] [0,0] type:#blend alphamultiplier:0.0
-- but the alpha from b_ is still stuck in there
display a_
Thanks, Richard
I might look into the DotNet option, seems like that should have some decent bitmap tools. For now I’m just making a copy of the rgb map, and then using setPixels() to copy the alpha line by line. Not optimal, but it’s getting the job done.
Thanks!
Inadvertant Thanks here!.. Was looking into doing something slightly similar to this but the code on this page gave me the foundation knowledge to do what I wanted to do but was unsure how!