[Closed] add one bitmap to another as alpha
@DennisT:the goal is # texture file with alpha as a final (tga, png, tiff, …)
Specifically a 32 bit tga that is then passed ( via hiddenDoscommand ) to a command line .dds converter
(AMD’s TheCompressonator )
@PolyTools3D :
tried your script and it does work.
But why does this use of rendermap preserve alpha while my previous attempt does not?
is it because of the use of the ” into: ” parameter?
max script help says:
If you specify the optional into: argument, the function renders the map into the supplied bitmap, taking size and other attributes from the existing bitmap. If you don’t, a new bitmap value is created using the size: and fileName: arguments in its creation.
so it appears that by using [into:<bitmap>] alpha is preserved
without [into:<bitmap>] render map generates only an rgb bitmap.
i’m thinking about using .NET for it. it will work faster probably. but using just built-in libraries you can’t save am image file in TGA format. the best alternative is PNG
my .NET-fu is too weak for bitmap operations.
I am experiencing no issues saving .tga from mxs.
It may be slower but faster than manually building game textures in photoshop et al.
@Mambo4: Yes, it may be a bug in the function, I can’t tell. But if you create the bitmap first it renders the alpha channel.
If you need to do bitmap manipulation (in this case or for other projects), I think it would be better to move ahead with .Net. Max is very limited in this field.
Although you can’t directly save .TGA file from .Net (as Denis mentioned), you could save a .PNG, open it in max and save it as .TGA.
I suspect the whole process will be slower in .Net, but you get much more options to manipulating the images.
Well, I do wish to improve my Dot Net Fu.
would you suggest starting with the MSDN page for the bitmap class? ?
My guess is that I’d create a dotNetObject or dotNetClass in mxs and use the methods and properties documented to do stuff…am I close to the mark?
You might also want to check the Graphics Class, which allows further image manipulation MSDN Graphics Class.
Here is a quick code to resize an existing bitmap and save it as .TGA as you described.
(
fn ResizeNetBitmap inputFileName outputFileName factor =
(
sourceImg = (dotnetclass "System.Drawing.Image").FromFile inputFileName
imgBits = sourceImg.PixelFormat
imgWidth = sourceImg.Width * factor
imgHeight = sourceImg.Height * factor
destImg = dotnetobject "System.Drawing.Bitmap" imgWidth imgHeight imgBits
graphic = (dotnetclass "System.Drawing.Graphics").fromImage destImg
graphic.CompositingQuality = graphic.CompositingQuality.HighQuality
graphic.SmoothingMode = graphic.SmoothingMode.HighQuality
graphic.InterpolationMode = graphic.InterpolationMode.HighQualityBicubic
rect = dotnetobject "System.Drawing.Rectangle" 0 0 imgWidth imgHeight
graphic.DrawImage sourceImg rect
tempFileName = outputFileName +".png"
destImg.Save tempFileName
sourceImg.Dispose()
destImg.Dispose()
graphic.Dispose()
-- Set TGA properties
Targa.setColorDepth 32
Targa.setCompressed true
Targa.setAlphaSplit false
Targa.setPreMultAlpha false
tempImg = openBitMap tempFileName
close tempImg
deleteFile tempFileName
outputBitmap = copy tempImg
outputBitmap.filename = outputFileName
save outputBitmap
close outputBitmap
freeSceneBitmaps()
gc light:true
)
ResizeNetBitmap @"C: est.tif" @"C: est_out.tga" 0.5
)