ScriptSpot

Forum topic · General Scripting

Combining or overlaying images through script?

By Haider of Sweden · 2016-02-20

Description

Does Maxscript have the ability to overlay a transparent PNG on top of another image, like a stamp or such?

Comments (3)

With .NET...

TsveTan · 2016-02-22

I am sure you can do this task with the native Maxscript functions, but at the moment I can give you a hint with .NET. I hope can recall correct...
At first create graphics class:
g = dotnetclass "system.drawing.graphics"
Then create a new bitmap or from file such as:
b = dotnetobject "system.drawing.bitmap" 256 256
Or... b = (dotnetclass "system.drawing.image").fromfile "c:\\myImage.bmp"
Next create the graphics inherited object:
gfi = g.fromimage b
Now you can paint over this image using the graphics object gfi.
gfi.drawimage "c:\\myStamp.png"
....
Just examine the graphics drawing methods in the Listener: showmethods gfi.
There are many drawing methods. You should be able to specify the x, y coordinates, maybe with this method, just take a look.

To be clear

TsveTan · 2016-02-22

use b.save "c:\\myImage.bmp" to save the file.

.

Haider of Sweden · 2016-02-22

I got the help I needed on CGTalk (credits goes to Jorge Rodríguez, PolyTools3D), and the solution looks like this:


(
fn BlendImages mBackImg mFrontImg =
(
result = copy mBackImg
pasteBitmap mFrontImg result [0,0] [0,0] type:#blend

close mBackImg
close mFrontImg

return result
)

fn SaveImage mImg mFileName =
(
mImg.filename = mFileName
save mImg
close mImg
)
back = openBitMap "$userscripts//splashes//_splash.png"	-- background image
front = openBitMap "$userscripts//splashes//_header.png"	-- alpha image

img = BlendImages back front
SaveImage img "$userscripts//splashes//splash.bmp"
)