On Sat, 2011-07-16 at 21:11 -0400, Markus Schulz wrote:
> Hello,
> 
> I'm not very experienced with Vala or GTK and I was trying to display a
> jpg picture from a sqlite db... thanks the the Internet I was able to
> find some code from different sources to get it to work:
> 
>                 unowned uint8[] data = (uint8[]) stmt.column_blob(9);
>                 data.length = stmt.column_bytes(9);
>                 var data2 = data;
>                 FileUtils.set_data("temp.jpg", data2);
>                 Pixbuf pixbuf = new
> Pixbuf.from_file_at_scale("temp.jpg",320,240,true);
>                 var image1 = builder.get_object ("image1") as Gtk.Image;
>                 image1.set_from_pixbuf(pixbuf);
> 
> However I'm not happy to have to save the data to a file... to load it
> again to display it. (I consier this a workaround)
> 
> I'm sure there is a more elegant way doing this, could someone please
> give me a hint or point me in the right direction on how to do that.

You could use GLib.MemoryInputStream.from_data (it's in GIO) to load
your data into a GLib.InputStream, then use Gdk.Pixbuf.from_stream to
get your pixbuf.

If performance is critical (and you're willing/able to write some
bindings) it should be possible to wrap the sqlite3_blob struct in a
GInputStream subclass. Actually, I think I'll look into doing that for
SQLHeavy--thanks for the idea ;)


-Evan

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to