Notifications
Clear all

[Closed] Tranfering Maxscript bitmap to DotNet image with Alpha Channel

I had found this code snipit in another forum, for copying a Maxscript bitmap into a DotNet image object:


	setClipboardBitmap  bm -- Copy the bitmap to the clipboard to pass it to dotNet	
	local clipboardObj = dotNetClass "System.Windows.Forms.Clipboard"  -- Create a dotNet clipboard object.	
	local imgObj = clipboardObj.GetImage() -- Get the image from the clipboard into a dotNet image object.

But evidently it doesn’t transfer the alpha channel? Does anyone know how to get the alpha channel to transfer as well?

Thanks!

1 Reply

I’m not sure you can John,

 My efforts at this always seem to return no alpha channel when converting using this method to a dotnet image. I've tried external image libraries also, taking a TGA and reading it to a memorystream. I still was unable to 'embed' the alpha channel. I'm not sure what you are using this for, but this is the workaround I have used. 
 
 A picturebox/dotnetcontrol will display a png image natively with alpha, however you have to save it out first.If you dedicate a temporary file as a save point, you can enable the alpha on the max PNG interface. Then, if you have a 32bit bitmap (from a TGA for example) it will save out the PNG with the correct transparency. 
 
 I used this method for a utility i wrote that we use here at work. It is for generating folders of flat opacity mapped planes with aspect wiring. this is the interface with a folder full of TGAS - Both viewers are DotNet controls. (click for larger view)
 
 [[img] http://www.lonerobot.com/images/fbhhsmall.jpg[/img]]( http://www.lonerobot.com/images/fbhhsmall.jpg[/img]](  g"/> )

 
 
 Since it's only for viewing purposes, it works for what i need. When the thumbnail is clicked, i save the bitmap to a temporary png file and then display it in the picturebox. It is almost immediate, certainly not slow. The picturebox itself is an inherited control but you could get the photoshop style checkerboard effect with a tiled bitmap. Then, in the thumb event handler, I run -
   
     --detect if the bitmap has alpha
      if BMPSource.hasalpha then
     	(  
     	 -- copy the bmp so it isnt locked on save
     	local BMPSaveMap = copy BMPSource
     	-- the filename is a struct memeber in my case, just replace with the path string
     	-- ie "c:\	empPNG.png"
     	BMPSaveMap.filename = Flatbot.PictureboxTempFilename
     -- set the png interface to save alpha
     	pngio.setAlpha true
     --save and cleanup memory
     	save BMPSaveMap
     	close BMPSaveMap
     	close BMPSource
     	return true
     	)
 the function returns true if the png has saved, as then i can check this and just set the picturebox/dotnetcontrol to display the saved image from the temp location.