Re: [Vala] Genie + Gtk: Image Base64



----- Original Message -----

From: "webierta gmail com" <webierta gmail com>
Sent: Wednesday, 8 March 2017, 10:59
Subject: [Vala] Genie + Gtk: Image Base64

I would like to know if in Genie (with Gtk +) I can visualize an image
that I have as a string in base64 format?

I tried to use Base64.decode like this:

Decoded: string = (string) Base64.decode ("iVBORw0KGgoAAAAN ...")

But I do not know if this can be translated somehow to Gdk.Pixbuf?


Base64.decode returns an array of unsigned char (uchar[]). This is the
same as uint8[], also known as a buffer. Instead of casting to string
assign the data to a buffer and then use MemoryInputStream:

[indent=4]
uses Gdk

init
    data:array of uint8 = Base64.decode ("iVBORw0KGgoAAAAN ...")
    var stream = new MemoryInputStream.from_data( data )
    try
        var image = new Pixbuf.from_stream( stream )
    except err:Error
        print( err.message )

You dummy data gives me:
Premature end-of-file encountered

So it kind of works, hopefully it will with a real image.

Al


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