Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
annadanesh
Posts: 82
Registered: ‎01-11-2013
My Device: DevAlphadevice

how to save QBytearray as image format(png or jpg) in filesystem

Hello all,

 

I am trying save QBytearray as image format(png or jpg) using following code but after writing ,file is empty so plz suggest me solution

QFile  outFile(filePath + fileName);

QImage image;

image = QImage::fromData(data);

if (outFile.open(QIODevice::WriteOnly))
                    {
                      image.save(&outFile, "PNG"); // or "PNG"
                      outFile.close();
                    }

Developer
kunal_one
Posts: 145
Registered: ‎12-23-2012
My Device: BB10 Dev Alpha

Re: how to save QBytearray as image format(png or jpg) in filesystem

I think you can simply use, following API

 

bool QImage::save(const QString & fileName, const char * format = 0, int quality = -1) const

 

You code will be something like this,

 

QImage image = QImage::fromData(data);

image.save(filePath + fileName, "PNG"); // or "PNG"

 

I have used such code, works perfectly.