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
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone
Accepted Solution

Write image to File

Hi,

 

   I'm having an image with me and I would like to save it in a path. I was able to get the datastream of that path.

 

QFile qFile("file://" + workingDir+ "/temp.jpg");
	if (!qFile.open(QIODevice::WriteOnly))
	         return;
	 QDataStream out(&qFile);

 

From then, I'm unable to crack how to write my Image which is present in my object to the QDataStrean.

 

 Please help me out.

 

Thanks,

Sha

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

Re: Write image to File

a QImage can directly save to a file
http://harmattan-dev.nokia.com/docs/library/html/qt4/qimage.html#save-2
----------------------------------------------------------
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: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: Write image to File

You can also use ImageConverter class to write Image into the file.
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Write image to File

[ Edited ]

Can you please post me a sample code snippet  to use imageconverter

 

Regards,

Sha.

Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: Write image to File

Try this (where imageData is of type ImageData, and outputFilePath is of type QString):

ImageConverter::encode (QUrl::fromLocalFile (outputFilePath), imageData, 75);
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Write image to File

Is there any way to convert Image to imageData. I found a way for Qimage but no luck for Image .
Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: Write image to File

Seems there is no trivial way to do that. But you can store your data as ImageData.
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Write image to File

Finally I figured a wayto get Imageata and saved it into the Disk