[Gtk-sharp-list] pixbuf/pixbufloader from stream help

Mauricio Henriquez mhenriquezs at terra.cl
Tue Jun 3 09:39:40 EDT 2008


Hi Guys:

As I explain in my previous post, right now gtk#/mono have issues about 
build a pixbuf using the byte[] contrcutor, so I 'm searching for 
alternatives, right now focused in build the pixbuf from a stream adn I 
realy need some help becouse with diferent aproach I can't get it and 
obviously I'm doing something wrong.

First I try building a PixBufLoader from a byte[] buffer:
Gdk.PixbufLoader pbL = new PixbufLoader(buffer, ImageWidth, ImageHeight);
This allways return me "Image has zero width", don't know what is my 
mistake...

Second: First be sure that the stream is correct using GDI+ :-S :
BitmapData bd = bitmapBuffer.LockBits(new System.Drawing.Rectangle(0, 0, 
ImageWidth, ImageHeight),
                                           ImageLockMode.WriteOnly, 
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Marshal.Copy(buffer,0,bd.Scan0,ImageWidth*ImageHeight*3);
bitmapBuffer.UnlockBits(bd);
MemoryStream mstr = new System.IO.MemoryStream();
bitmapBuffer.Save(mstr, System.Drawing.Imaging.ImageFormat.Bmp);
..then only for test:
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(mstr);
returnImage.Save("testStr.bmp");
This work, so the stream is corect

Third try: Use the memory stream to try to build the Pixbuf or the 
Pixbufloader:
Gdk.PixbufLoader pbL = new PixbufLoader(mstr, ImageWidth, ImageHeight);
or
internalPixbuf = new Pixbuf(mstr, ImageWidth, ImageHeight);
or just: Gdk.Pixbuf pb = new Pixbuf(mstr);
Allways return me "GLib.GException: Unrecognized image file format"

Finall test: Try to use other type to build from stream like Gtk.Image:
Gtk.Image img = new Gtk.Image(mstr);
This seems to work, but I still can't get the pixbuf from this!!!, 
img.Pixbuf return null (I supose that is becouse the image is not 
builded from a pixbuf..)...

So the question is, how can I really build a pixbuf/pixbufloader from a 
stream and/or get the PixBuf from a Gtk.Image that was builded from a 
stream?

Please, please I really need some help here, this is driving me crazy, I 
need to get working this widget, previously in mono-1.2.6 I I only use 
ONE line to so this:

internalPixbuf = new Pixbuf(buffer, Colorspace.Rgb, false, 8, 
ImageWidth, ImageHeight, ImageWidth * 3, null); //buffer of byte[] type

I know with the "byte[]" bug/problem I really need an alternative, and I 
know that is posible to build this thing from a stream so please give 
any sugestion..

In advance, thank you very much...

Mauricio



More information about the Gtk-sharp-list mailing list