Gtk.Image and System.Drawing.Bitmap

View: New views
5 Messages — Rating Filter:   Alert me  

Gtk.Image and System.Drawing.Bitmap

by spaceyguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it possible to create a Gtk.Image using a System.Drawing.Bitmap object as the source of the image? If not is there some kind of workaround which I can use to do this.

Re: Gtk.Image and System.Drawing.Bitmap

by Michael Hutchinson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

On Jul 7, 2009 5:16 PM, "spaceyguy" <spaceyguy@...> wrote:


Is it possible to create a Gtk.Image using a System.Drawing.Bitmap object as
the source of the image? If not is there some kind of workaround which I can
use to do this.
--
View this message in context: http://www.nabble.com/Gtk.Image-and-System.Drawing.Bitmap-tp24366793p24366793.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list


_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Gtk.Image and System.Drawing.Bitmap

by spaceyguy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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, 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.

Re: Gtk.Image and System.Drawing.Bitmap

by Stephen A. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> 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, 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

Sent from the Mono - Gtk# mailing list archive at Nabble.com.

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list



_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: Gtk.Image and System.Drawing.Bitmap

by Stephane Delcroix :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

the other option is to use Gtk.DotNet.Graphics.FromDrawable ()

s

On Mon, 2009-07-06 at 20:59 -0700, spaceyguy wrote:
> Is it possible to create a Gtk.Image using a System.Drawing.Bitmap object as
> the source of the image? If not is there some kind of workaround which I can
> use to do this.

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list