PDA

View Full Version : QImage crash when the format is "Format_Indexed8"



stereoMatching
2nd June 2012, 21:35
os : win7 64bits
compiler : mingw4.6.2
qt version : qt4.8.1(the dll and and the lib haven't rebuild by mingw4.6.2)



#include <QtGui/QApplication>
#include <QtGui/QImage>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QImage src("../GIL_with_Qt/images_00/lena/lena.jpg");
src = src.convertToFormat(QImage::Format(3) );
QImage dst(src.size(), src.format());

dst.save("E:/lena/lena_Format_Indexed8.jpg");
return a.exec();
}


This will cause the program crash, what kind of mistake do I make?
Thank you very much

ChrisW67
3rd June 2012, 08:19
Crashes here too but it doesn't do anything useful as far as I can see.

You load a full colour JPEG image, ask Qt to convert it to a palette-base image, create an uninitialised blank image of the same size and format and attempt to save that as a JPEG file. Attempting to save that new image is causing the crash: JPEG is not a good storage for a 8-bit indexed image although it should not crash. Saving as PNG does not crash but does not do what I think you are expecting. If you want to save the converted image then you do not need dst at all: just save src.

BTW: You should use QImage::Format enum constants rather than an integer magic number, e.g. QImage::Format_Indexed8 rather than 3.

stereoMatching
3rd June 2012, 11:24
Thanks for your reply, I know it didn't do anything useful of my codes snippet,
I only post the part of the codes which make it crash.I use magic number instead
of QImage::Format_* because I need to iterate through the format in my original
codes.

Is this a bug?Should I report it?If I should, where is the right place to report?
Thanks a lot.