Re: [Vala] sqlite blob to GTK image


On 17 July 2011 03:11, Markus Schulz <schulz alpharesearch de> wrote:

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
               var image1 = builder.get_object ("image1") as Gtk.Image;

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.


PS: this is for a ham radio exam study program: that is still very alpha

I had the same issue a couple of weeks ago.
Here is the code I'm using:

            Gdk.Pixbuf pb;
            #if (GDKPIXBUF_HIGHERTHAN_212)
                var imgstream = new
GLib.MemoryInputStream.from_data(imgdata, null);
                pb = new Gdk.Pixbuf.from_stream(imgstream);
                FileUtils.set_data(TEMP_IMG, imgdata);
                pb = new Gdk.Pixbuf.from_file(TEMP_IMG);

Hope it helps,
Iñigo Serna

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]