Notifications
Clear all

[Closed] dotNet bitmap functions returning undefined

Hi everyone.

I’m revisiting an old script that worked without error in Max 2011, but in 2014 and higher it’s throwing a lot of exceptions.

Here’s a small example:


// Create bitmap
bm = bitmap 28 28 color: (col = ((colorMan.getColor #background)*255)as color) // <-- Sidenote: This is no longer getting the correct button UI color for me either
// Send to clipboard
setclipboardBitmap bm
// Make dotNet bitmap
b = clipboard.GetImage() // Sometimes b is returning undefined, sometimes b is "dotNetObject:System.Drawing.Bitmap"
// Manipulate bitmap
b.RotateFlip (dotnetclass "System.Drawing.RotateFlipType").Rotate90FlipNone // When b returns "dotNetObject:System.Drawing.Bitmap" then the rotate stuff returns undefined :\

Is this happening for anyone else? If so, what changed since 2011 and how can I re-write the code to make it work like before? The weird thing is that sometimes it does work but it’s very inconsistent and I’m not well versed enough in dotNet to figure out why :\

I’ve spent a few days searching and trying to figure it out but I’m not making any progress.

3 Replies
 j83

This may or may not be related, but at times getting data from the clipboard can at times return undefined.

You can try something like this.


local loadBitmapRetryCount = 4
                  
local loadedImage = undefined
for i = 1 to loadBitmapRetryCount do
(
   if (undefined == loadedImage) then
   (
      loadedImage = loadBitmapFunction filePath
   )
   else
   (
      break
   )
)
useBitmapFunction loadedImage

works ok for me


fn dotnetFlipBitmap theBmp =
(
   setclipboardBitmap theBmp 
   b = (dotnetclass "Clipboard").GetImage()
   b.RotateFlip (dotnetclass "System.Drawing.RotateFlipType").RotateNoneFlipXY
   (dotnetclass "Clipboard").SetImage b
   getclipboardBitmap() 
)
bm = bitmap 28 28 color:red
dotnetFlipBitmap  bm

That’s because since 2017 you’re supposed to use #button for button bg color, #background and #window are deprecated in favor of #backgroundOdd.