Question

I need to show a png image in a QML page using a QByteArray passed from c++ routines to QML.How can i do this.? Please help me with this guys..

Was it helpful?

Solution

Assuming you have your data in a QByteArray named data, this should work:

QImage image;
image.loadFromData(data);
const QImage swappedImage = image.rgbSwapped();
const bb::ImageData imageData = bb::ImageData::fromPixels(swappedImage.bits(), bb::PixelFormat::RGBA_Premultiplied, swappedImage.width(), swappedImage.height(), swappedImage.bytesPerLine());

_image = bb::cascades::Image(imageData);

You can now display _image in an ImageView in your QML code. To achieve this, you'll have to convert it in a QVariant: QVariant::fromValue(_image);. Once done, you can display it in any ImageView. I assume you have an object named feed which has an image property (QVariant):

ImageView {
    image: feed.image
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top