Image handling without System.Drawing.Common for Net7.0 and .NetFX

hey All

I’ve been converting our old winforms project to ETO and .net7/fx, and have built a large and mostly working ETO forms GUI, project, in 4.8 it runs great but for net7.0 im stuck at the fact that since 6.0 System.Drawng.Common is no longer cross platform compatible.

in the two lines bold below im hard up against a wall. its grabbing a view from Rhino and storing it in an ETO image holder. Any suggestions?

// Capture the image from the viewport
 **var capture = viewport.CaptureToBitmap(new System.Drawing.Size(width, height));**
 if (capture == null)
 {
     RhinoApp.WriteLine("Failed to capture the viewport image.");
     return null;
 }

 // Reselect the previously selected objects
 foreach (var id in objectIds)
 {
     doc.Objects.Select(id);
 }

 // Convert the System.Drawing.Bitmap to Eto.Drawing.Bitmap
 using (var stream = new MemoryStream())
 {
     **capture.Save(stream, System.Drawing.Imaging.ImageFormat.Png);**
     stream.Position = 0;
     var etoBitmap = new Eto.Drawing.Bitmap(stream);
     return etoBitmap;
 }

And then again in actually trying to register the panel at all that is insisting on a System.Drawing.Common icon…

Panels.RegisterPanel(PlugIn, typeof(ViewPanel), “Palloys Uploader”, Properties.Resources.Palloys);

nevermind self resolved used ironsoftware.system.drawing.
dropped in and just worked.

would be nice if these could be handled in ETO…

Hey @ChristopherBotha what version of Rhinocommon are you referencing and which Rhino are you testing in? This System.Drawing.Common issue is a Rhino issue, not Eto afaik. I thought this was resolved in the latest versions.

You could also include it conditionally for net7.0 as a workaround.

	<ItemGroup>
		<PackageReference Condition="'$(TargetFramework)' == 'net7.0'" Include="System.Drawing.Common" Version="7.0.0"/>
	</ItemGroup>

There is a ToEto() extension you can use so you don’t have to go through all of this.

var etoBitmap = capture.ToEto();
1 Like

latest rhino 8 in both cases being referenced and used

ill convert the code to use your second method though which solves some of the issue
(i since ran itno other instances, colours inteh e.DrawXXXXX functions in displaypipeline only accept system.drawing.colors as well not eto. unless there is another workaround i missed

There are ToEto() functions for many System.Drawing items, and also there are ToSD() functions for many Eto items too which may help :slight_smile:

1 Like

i tried that using et.drawing.color then within the pipeline code use .ToSystemDrawing, but that means i need to reference system.drawing which means im not cross platform compatible?

I’ve done some reading. And you’re totally right.
System.Drawing.Common doesn’t work on mac after net6.0 as mentioned in detail here.

I think @curtisw might know. I’ve done some testing and I still seem to be able to create a System.Drawing.Bitmap on mac in Rhino 8 net7.0 without issue, which makes sense as I never thought I’d had an issue doing this.

I think you should be fine using System.Drawing.Common for Rhino Plugins on Mac/Win.

We ship our own version of System.Drawing on Mac