"Downloading" a GdkTexture

Let’s say I want to display a image coming from the web.

A reasonable approach in GTK+ 3 was to use Soup to load the image into a MemoryInputStream and use this to create a GdkPixbuf. [1]

However, I noticed that GdkPixbuf is not longer considered to be part of main GTK and that GdkTexture is the new object to be used for images.
However, GdkTexture can be only constructed from a GdkPixbuf or a local file. I am aware that from_bytes exists, but this is noted to be for version 4.6.0?

So, the question is: What would be your approach to storing a web image in a GdkTexture? Downloading the file to /tmp and loading it from there? Create a GdkPixbuf and then converting it to a GdkTexture (which sounds somewhat silly)? Or do I miss something obvious here?

[1]: “Reasonable” as in done this way by Cawbird, the application I am trying to port to GTK4.

That’s not really correct. GdkPixbuf hasn’t never been part of GTK; it was in the same repository, but was split more that 10 years ago. You can still use it to load various image formats.

In GTK4, we dropped a lot of the internal use of GdkPixbuf, because all we care about is taking the pixel data and pushing it to the GPU as fast as possible; that’s why GdkTexture exists. GdkTexture is constructed out of raw pixel buffers, and it’s meant to be an immutable, write-only storage of texture data, like a GL texture object.

If you have image data from some random source, in some random format, you can still use GdkPixbuf to load it and decode it; once you have the pixel buffer, and you wish to display it inside a GTK widget, then you should take that pixel buffer and put it inside a GdkTexture.

Thanks for the answer!
Guess I use GdkPixbuf as a decoder then.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.