Load Gdk::Pixbuf from string

Hi all,

I have a Ruby string containing an image. The format, width, height,
bits
per sample, rowstride and so on, are not known in advance.

If I save my string to a file and create a pixbuf with
Gdk::Pixbuf.new(myfile), this works, but I would like to get my pixbuf
without touching the hard disk. Is that possible?

Any help appreciated.

Thank you,
Mathieu B.

this is how i did it:
a=Array.new
string.each_byte{|v|a.push(v)}
pixdata=Gdk::Pixdata.deserialize(a)
pb=pixdata.to_pixbuf(true)
im=Gtk::Image.new(pb)

If it’s an encoded image (e.g. JPEG, PNG etc) rather than a serialized
GdkPixdata, you’ll want to use Gdk::PixbufLoader

loader = Gdk::PixbufLoader.new
loader.write(data)
loader.close

pixbuf = loader.pixbuf

2009/1/8 Dobai-Pataky B. [email protected]

Thank you to both of you for your quick reply. Yes, my string contains
the
dump of an encoded file. It’s not a string of pixels. The PixbufLoader
solution made the trick! I should not work when I’m too tired, this
makes me
misread the documentation :wink:

2009/1/8 Geoff Y. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs