Advertisement
rotrevrep

load pixbuf from data (avoids PixbufLoader errors)

Oct 12th, 2013
3,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.64 KB | None | 0 0
  1.     async Gdk.Pixbuf pix_from_data (uint8[] data){
  2.         FileIOStream stream;
  3.         var file = File.new_tmp ("totoXXXXXX", out stream);
  4.         stream.output_stream.write (data);
  5.         stream.seek (0,SeekType.SET);
  6.         Gdk.Pixbuf? pix = null;
  7.         if(data.length > 0)
  8.             pix = yield new Gdk.Pixbuf.from_stream_async (stream.input_stream, null);
  9.         else
  10.             pix = new Gtk.Image.from_icon_name ("image-missing",Gtk.IconSize.MENU).pixbuf;
  11.         return pix;
  12.     }
  13.  
  14. /***/
  15.  
  16. Gtk.Image imgTag = ...
  17. uint8[] buffer = ...
  18. /***/
  19.  
  20. pix_from_data.begin (buffer,(obj,res)=>{
  21.     try {
  22.         imgTag.pixbuf = pix_from_data.end(res);
  23.     }catch(GLib.Error e){
  24.         print("%s\n",e.message);
  25.     }
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement