'System.Drawing' object has no attribute 'Bitmap' (Rhino 8 WIP)

Hi @dale,

when i try to capture to bitmap and save, i get this error:

‘System.Drawing’ object has no attribute ‘Bitmap’

to repeat, please use below Python code from _EditPythonScript:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import System

def DoSomething():
    
    view = scriptcontext.doc.Views.ActiveView
    size = scriptcontext.doc.Views.ActiveView.ActiveViewport.Size
    bitmap = view.CaptureToBitmap(size, False, False, False)
    if bitmap:
        
        desktop = System.Environment.SpecialFolder.Desktop
        file_path = System.Environment.GetFolderPath(desktop)
        file_name = "CaptureToBitmapTest.png"
        file_path_name = System.IO.Path.Combine(file_path, file_name)
        if file_path_name:
            System.Drawing.Bitmap.Save(bitmap, file_path_name)
        
DoSomething()

thanks,
c.

Hi @clement,

I am not seeing this with an internal WIP build from today. You might test against this week’s WIP when available.

– Dale

Hi @dale, thank you. I’ll report back once i have it.

_
c.

.NET 7 eventually drops System.Drawing.Commons support on macos. If you’d like your plugin to work on macos, it’s better to switch to another graphics framework.

Hi @gankeyu, my report is happening on Windows 10. I’ve not tried V8 on Mac yet but if view.CaptureToBitmap returns a System.Drawing.Bitmap i would expect it to be saveable using bitmap.Save. If the framework is Eto in the future on Mac, the call to save would be identical i guess…

_
c.

Really? @curtisw this might be the single reason not to go to .NET 7 if that is truly the case.

  • This switch is only available in .NET 6.
  • In 2022 .NET 7 projects using System.Drawing.Common began throwing PlatformNotSupportedException

I think you can still use the System.Drawing.Common DLL from .NET 5 to provide, sort of, support. But that’s not a good practice…

Besides, the support of .NET 6 ends on Nov, 2024, a date I suppose Rhino 9 hasn’t come out. So there would be a time when Rhino 8 is still in lifecycle but its underlying .NET 6 is out of support.

Don’t worry everyone, we have our own implementation of System.Drawing on macOS so Grasshopper and all of the plugins will work the same even when we inevitably update to .NET 7. We never relied on the mono implementation for Rhino 7 nor the .NET 6 version of System.Drawing.Common for Rhino 8.

As for the python script, it is working for me with the latest WIP on Mac, but on Windows it looks like we need to fix that up when running in .NET 6+. I’ve added RH-71392 to get that fixed up.

Thanks for reporting the issue @clement!

2 Likes

@clement by the way, you can add the following lines to get it working in the meantime:

import clr

clr.AddReference("System.Drawing.Common")

Hope this helps!

I’m not really concerned about “standard support” versus “long term support” from Microsoft for these frameworks. We’ve never really had any specific support from Microsoft in the past for .NET frameworks beyond their regular updates.

Thank you @curtisw, below seems to have cured the issue for now using Rhino 8 for Windows WIP (8.0.22319.12305, 2022-11-15)

if not hasattr(System.Drawing, "Bitmap"):
    clr.AddReference("System.Drawing.Common")

_
c.