Forum: Ruby-Gnome 2 load Gdk::Pixbuf from string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mathieu B. (Guest)
on 2009-01-08 06:05
(Received via mailing list)
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.
Dobai-Pataky B. (Guest)
on 2009-01-08 11:12
(Received via mailing list)
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)
Geoff Y. (Guest)
on 2009-01-08 12:34
(Received via mailing list)
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. <removed_email_address@domain.invalid>
Mathieu B. (Guest)
on 2009-01-08 14:41
(Received via mailing list)
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 ;-)

2009/1/8 Geoff Y. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.