Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One ugly, but working, way is to store the bitmap as a PNG in a <a href="http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=vs.110%29.aspx" rel="nofollow"><code>MemoryStream</code></a>.</p> <p>To save the <a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx" rel="nofollow"><code>Bitmap</code></a>, you can use the <a href="http://msdn.microsoft.com/en-us/library/ms142147%28v=vs.110%29.aspx" rel="nofollow"><code>Save</code> method</a>:</p> <pre><code>b.Save(myMemoryStream, ImageFormat.Png); </code></pre> <p>That was easy enough. Loading the PNG data into the <a href="http://docs.go-mono.com/?link=T%3aGdk.Pixbuf" rel="nofollow">Gdk# <code>Pixbuf</code></a> is also rather easy; you can use the appropriate constructor:</p> <pre><code>Pixbuf pb = new Gdk.Pixbuf(myMemoryStream); </code></pre> <p>You may need to reset the memory stream so the reading position is at the start of the stream before creating the <code>Pixbuf</code>.</p> <p><em>A word of caution: I do not consider this the best, or even a "good" solution. Transferring data between two object-oriented data structures by serializing and deserializing the data has a certain code smell to it. I genuinely hope someone else can come up with a better solution.</em></p> <p>EDIT: As for the used libraries: This answer uses only plain GDI+ (<code>System.Drawing.Bitmap</code>) and Gdk# (<code>Gdk.Pixbuf</code>). Note that a <a href="http://docs.go-mono.com/?link=T%3aGtk.Image" rel="nofollow"><code>Gtk.Image</code></a> is a widget that displays a <a href="http://docs.go-mono.com/index.aspx?link=T%3aGdk.Pixbuf" rel="nofollow"><code>Gdk.Pixbuf</code></a>. As such, <code>Gtk.Image</code> is the equivalent of Windows Forms' <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox%28v=vs.110%29.aspx" rel="nofollow"><code>PictureBox</code></a>, whereas <code>Gdk.Pixbuf</code> is roughly equivalent to Windows Forms' <a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx" rel="nofollow"><code>System.Drawing.Bitmap</code></a>.</p> <p>EDIT2: After testing your code, I have found that there are three additional preconditions to ensure before you can run your minimum example:</p> <ul> <li>As suspected above, you must reset the stream position to the beginning of the <em>after</em> saving your <code>Bitmap</code> and <em>before</em> loading your <code>Pixbuf</code>: <code>ms.Position = 0;</code></li> <li>You must compile the application for <strong>x86</strong> CPUs.</li> <li>You must invoke <code>Gtk.Application.Init();</code> before you do anything with <code>Pixbuf</code>.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload