PDA

View Full Version : Can't save image by QImage(save function always return 1)



stereoMatching
28th May 2012, 16:19
QImage src("../GIL_with_Qt/images_00/lena.jpg"); //can load the image
std::cout<<src.save("C:\lena2.jpg")<<std::endl; //always return 1


The codes could load the image perfectly, but can't save it anyway.
Besides, I have only load two kinds of format from the QImage.
Format_Indexed8 and Format_RGB32, I tends to transform the format
of the image by "save"(could I?) because some formats of the images are rare.
But it wouldn't work even "save" always return 1.

How could I solve the problem?
Thanks

mvuori
28th May 2012, 20:01
Easy. Backslashes need to be escaped in C++: "C:\lena2.jpg" -> "C:\\lena2.jpg".

ChrisW67
28th May 2012, 23:54
... or use forward slashes for file paths everywhere in your code, avoid the missing backslash pain, and increase portability (although not with explicit drive letter references). Also, on some versions of Windows, and in many corporate environments, writing the the root of the C: drive is forbidden for non-privileged users.

stereoMatching
29th May 2012, 12:25
Thank you very much, I solve my problem.
But I still have other question, how could I change
the format of the picture by Qt?I would like to
read the other format of the QImage support,
but some of them are hard to find, so I want to transfer
them to the format I lack and try to do some pixel manipulation
about them.

ChrisW67
29th May 2012, 23:37
:confused: I'll answer the obvious question. The remaining statements make little sense.


how could I change the format of the picture by Qt?
Load an image in one format using QImage::load() or QImage::loadFromData() and write the image to file in another format using QImage::save(). The supported formats are in the docs for QImage and QImageReader.