[Gtk-sharp-list] Gtk.Image and System.Drawing.Bitmap

StApostol stapostol at gmail.com
Wed Jul 8 05:03:11 EDT 2009


You can get a raw IntPtr to the System.Drawing.Bitmap data, using:
var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
PixelFormat.Format32bppRgba, ImageLockMode.ReadOnly);
// data.Scan0 contains the pointer
IIRC you can construct a Gtk.Image from a raw pointer (I'm pretty sure I
have used this before). Just make sure the pixel formats match and pass this
pointer along with data.Stride (if necessary).
Don't forget to unlock and dispose the bitmap when you are done:
bmp.UnlockBits(data);
bmp.Dispose();

On Wed, Jul 8, 2009 at 6:47 AM, spaceyguy <spaceyguy at gmail.com> wrote:

>  Michael Hutchinson wrote:
>  There are a few ways to do this, though IMO all are suboptimal. The
> easiest would be to save the Bitmap to a MemoryStream then load the
> Gtk.Image from that stream. FWIW, why do you have a Bitmap? Depending on
> what you're doing, you may be able to go straight to the Gtk.Image.
>
> Ive been playing around with the facebook api, using something the Facebook
> Developer Toolkit <http://facebooktoolkit.codeplex.com/>, and it can
> return a Bitmap object for getting a profile picture. I wanted to know if it
> would be easier to just use the Bitmap or use the url instead.
> ------------------------------
> View this message in context: Re: Gtk.Image and System.Drawing.Bitmap<http://www.nabble.com/Gtk.Image-and-System.Drawing.Bitmap-tp24366793p24384865.html>
> Sent from the Mono - Gtk# mailing list archive<http://www.nabble.com/Mono---Gtk--f1373.html>at Nabble.com.
>
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20090708/ce786014/attachment.html 


More information about the Gtk-sharp-list mailing list