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
New Developer
Posts: 23
Registered: ‎07-05-2013
My Device: Z10
My Carrier: Binus
Accepted Solution

How to save Image from QByteArray?

[ Edited ]

Hello there,

 

How to save JPG image from QByteArray data to BB10 device?

 

Many thanks before :smileyhappy:

Developer
Posts: 16,679
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to save Image from QByteArray?

what do you mean with "save"?
if you want to write a QByteArray to the file system use QFile.
If you want to create an image object from the array use QImage::loadFromData
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19
Registered: ‎03-06-2014
My Device: blackberry z10 stl100-3
My Carrier: n/a

Re: How to save Image from QByteArray?

 

QByteArray array;  <--- this has the image data in byte form

 

QImage image = QImage::fromData(array, "BMP"); //original format was bmp for me, I convert to jpeg further down

QFile outFile("shared/photos/temp1.jpeg");

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

 

Let me know if this works, I just finished finished writing an app that lets a user sketch and doodle pictures with their finger and had this save function to debug it.

New Developer
Posts: 23
Registered: ‎07-05-2013
My Device: Z10
My Carrier: Binus

Re: How to save Image from QByteArray?

Thank you stephen, i tried your example code and it works! and then because of my curious, i tried to remove QFile from your example, and then it still works.. i think my fault is the wrong filename before. 

My code to be like this,

image.save("shared/photos/temp1.jpeg", "JPEG");

 

thank you all :smileyvery-happy: