Home > Blockchain >  use in memory file with QML's Image
use in memory file with QML's Image

Time:12-09

In my application I generate a lot of different images (I keep them as QImage objects) and I was wondering if it would be possible to use these objects more or less directly with QML Image? The only option I see is to write them to disk and then pass path to Image.source. Is there any trick to avoid it?

Additional info: apart from static QIMages I also plan to generate gifs and possibly other files (all in memory) which I'll try to use with AnimatedImage or MediaPlayer so workaround for static image only is not enough for me.

CodePudding user response:

I think what you're looking for is a QQuickImageProvider. It allows your QML app to request images/pixmaps from a C class that you provide. The data can then come from anywhere you like, including an in-memory QImage. The example provided here shows how to generate a pixmap on the fly and provide it to a QML Image object.

  • Related