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 Blondel
on 2009-01-08 05:05
on 2009-01-08 10:12
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)
on 2009-01-08 11:34
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 Balint <dpblnt@gmail.com>
on 2009-01-08 13:41
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 Youngs <g@intersect-uk.co.uk>
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.