Bitmap Alpha Pasting

Bitmap Alpha Pasting

lightcube
Advisor Advisor
543 Views
2 Replies
Message 1 of 3

Bitmap Alpha Pasting

lightcube
Advisor
Advisor

I've found some threads on the Internet discussing this issue, but I haven't actually solved it. I have a script that pastes a bunch of bitmaps as pieces onto another bitmap. The pastebitmap() function does not seem to keep the alpha channel of the pasted bitmaps regardless of the parameters I've passed. Most suggestions have been to use getPixels() and setPixels(). When I rewrote my code to use these instead, the same problem arises.

 

Here is the kind of scenario I'm trying to run: render 4 bitmaps (that result with alpha channels that are correct) then paste the 4 bitmaps as tiled pieces of a larger bitmap. That larger bitmap must have all the alphas for the original pieces.

 

I've read all the docs and read multiple threads across the net but no working examples.



Shawn Olson

Developer of Wall Worm
3ds Max plugins and Scripts

3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019

Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti
0 Likes
544 Views
2 Replies
Replies (2)
Message 2 of 3

miauuuu
Collaborator
Collaborator

Hi, Shawn!

 You can use pasteBitmap to transfer the alpha from one image to another.

 Here the code, thad DenisT gives to me. It works much faster than per pixel transfer.

 you have to change the code, so the next img, that is send to the bigger image to be placed in proper place.

[code]

(
    b1 = openBitmap "D:\\testImage.tga"
    b2 = openBitmap "D:\\testImage_alpha.tga"
    fn copyAlpha c1 p1 c2 p2 =
    (
        c2.a = c1.r
        c2
    )
    t1 = timestamp()
    pastebitmap b2 b1 [0,0] [0,0] type:#function function:copyAlpha
    display b1
    format "size:[%,%] time:%\n" b2.width b2.height (timestamp() - t1)
)

[/code]

 

This is not the best solution, but it is much faster than per pixels approach. For example, on my PC, when b1 and b2 are with 2160x4196px size, per pixel methods transfer the b2 into the alpha chanel of b1 for ~25sec. With the code above, for ~ 7 sec.

https://miauu-maxscript.com/
0 Likes
Message 3 of 3

lightcube
Advisor
Advisor

Thanks Kostadin. I actually saw your thread with Denis.

 

It turns out that my problem was a little more complex, and was not really an error with the functions mentioned here. I've solved it now. It was that calling rendermap() in MXS isn't returning a bitmap with valid alpha data. So I'm not sure why that is happening... but I do have a working solution.

 

I'll expound more of the real issue and solution I found later this week.



Shawn Olson

Developer of Wall Worm
3ds Max plugins and Scripts

3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019

Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti
0 Likes