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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
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..

 

 

 

 

 

 

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");
                }