Hi ![]()
I’m trying to use AdwAvatar to add pictures to my app from binary data I get from an HTTP request… But I had no luck.
I probably didn’t understood correctly. So here’s my current understanding;
- AdwAvatar use a Paintable to get the image with
set_custom_image. - Gdk.Paintable.snapshot use Snapshot to create Paintable object.
- snapshot.append_texture allow you to put a picture in a snapshot.
- You need a Gdk.Texture and a Graphene.Rect to use “snapshot.append_texture”
- You can use Gdk.Texture.new_from_bytes to create a texture from your Binary
- You need to convert your Bytes to GBytes with GLib.Bytes.new to use Gdk.Texture.new_from_bytes.
But so far, it doesn’t work. I don’t get errors; I just get no images on AdwAvatar.
Here’s my commented code;
# Get image binary
imageData = self.runGetQuery("/ocs/v2.php/apps/spreed/api/v1/room/" + child.find('token').text + "/avatar", 1)
# create GBytes from Bytes
avatarGBytes = GLib.Bytes.new(imageData)
# Create a texture from it
avatartexture = Gdk.Texture.new_from_bytes(avatarGBytes)
# Create a Snapshot
snapshot = Gtk.Snapshot.new()
# Create a Rect
avatarRect = Graphene.Rect.alloc()
avatarRect.init(0, 0, 64, 64)
# Combine texture and Rect to populate the Snapshot
snapshot.append_texture(avatartexture, avatarRect)
# Create a new Paint and add it the snapshot
pt = Gdk.Paintable.new_empty(64, 64)
pt.snapshot(snapshot, 64, 64)
# create the avatar Object
avatar = Adw.Avatar()
# Finaly; Set the image.
avatar.set_custom_image(pt)
Did I took the right path ? Could someone give some advices ?
Tank you