Confusion regarding Windows bitmaps, System.Drawing and Eto.Drawing

377 views
Skip to first unread message

john....@gmail.com

unread,
Jan 26, 2016, 4:21:06 AM1/26/16
to Eto.Forms
Hi all,

I've just recently found this excellent library and am getting my head around how things work.

I'm not clear though on the role System.Drawing plays vs Eto.Drawing. My goal is to have a single codebase for WinForms, Mac (MonoMac) and Linux (GTK3). I am using some bitmap operations and because I am referencing System.Drawing does that mean it will only work on Windows? I thought Bitmap operations were Windows specific?

So...

Should I remove my references to System.Drawing and System.Drawing.Imaging and replace them with Eto.Drawing and then convert my code to use the Eto methods?

Any by the way, this entire post was prompted because I'm trying to load a Windows bitmap into an Eto ImageView control and I cannot. There error I get is "Cannot implicitly converty type System.Drawing.Bitmap to Eto.Drawing.Image". Is there a way to do this?

Thanks so much for any sliver of help someone could provide :)

John



curtis

unread,
Jan 26, 2016, 2:49:01 PM1/26/16
to Eto.Forms, john....@gmail.com
Hi John,

Yes, in order for you to create cross platform applications you should use the Eto.Drawing namespace instead of System.Drawing.

So, you'd use Eto.Drawing.Bitmap.FromResource() to load from an embedded resource in your assembly, or, new Bitmap(Stream/FileName).  Be wary of loading bitmaps from filename and assuming the working directory - you should always load files using absolute paths to keep things working well cross platform.

You "can" use System.Drawing on most platforms (due to mono implementing most of its stack), and to convert to an Eto.Drawing.Bitmap, you can save the System.Drawing.Bitmap to a stream, then load it using Eto.Drawing.Bitmap.  It is definitely not as efficient as using Eto.Drawing directly though.  This adds a hefty dependency though and I usually recommend against doing this unless you have a ton of existing System.Drawing code that would be difficult to port over.

Hopefully this helps!
Curtis.

john....@gmail.com

unread,
Jan 27, 2016, 4:05:15 AM1/27/16
to Eto.Forms, john....@gmail.com
Hi Curtis, thanks so much for your help and explanation, that clears it up for me.

Best wishes from Australia
Reply all
Reply to author
Forward
0 new messages