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
Posts: 27
Registered: ‎03-27-2011
My Device: Z10,Q10,Z30
My Carrier: Verizon and ATT
Accepted Solution

Saving image with data in QVariant

JPEG image is converted into QVariant (with bb::cascades::Image) using the following code

 

//// m_image is bb::cascades::Image

 

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

 

Converted to QVariant using QVariant::fromValue(m_image)

 

The image is displayed in qml.( I cannot save the file immedietly after downloading as there will be a lot of images and I have to select and save. When the image is displayed its QVariant..

 

I would like to save this image, which later to be used as Contact Photo..

 

I saw the sample code

 

//imageData1 is QByteArray

Image image = QImage::fromData(imageData1, "BMP");
QFile outFile("shared/photos/temp1.bmp"); //change to your file path
outFile.open(QIODevice::WriteOnly);
image.save(&outFile, "JPEG");

 

I tried to convert QVariant to QByteArray using QVariant.toByteArray(). but it didnt work.

 

Any help will be really appreciated..

 

 

 

 

 

 

Highlighted
Developer
Posts: 27
Registered: ‎03-27-2011
My Device: Z10,Q10,Z30
My Carrier: Verizon and ATT

Re: Saving image with data in QVariant

The issue is resolved by keeping around ImageData data object instead of Image object. Using the following code....

 

QByteArray imageArray = ImageConverter::encode("image/jpeg", myImageData);
                QImage image = QImage::fromData(imageArray, "JPEG");
                QString imgPath = "shared/photos/"+myImageName+".jpg";


                if(!(QFile::exists(imgPath)))
                {
                    QFile outFile(imgPath);

                    outFile.open(QIODevice::WriteOnly);
                    image.save(&outFile, "JPEG");
                }