Re: [Vala] sqlite blob to GTK image
- From: Evan Nemerson <evan coeus-group com>
- To: Markus Schulz <schulz alpharesearch de>
- Cc: vala-list gnome org
- Subject: Re: [Vala] sqlite blob to GTK image
- Date: Sat, 16 Jul 2011 21:59:47 -0700
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]