PDA

View Full Version : Problem when saving bmp files



cdlaweed
16th March 2011, 17:53
Hi,

I have a QImage generated from a char* data array. When trying to save it to the bmp the file is correctly created but is not readeable by the window wiewer (paint open it but the data is crappy).

I guess that my QImage is not correctly initialised, but I don't find Where :(

Here is a part of my code:


// allocate the memory for the input picture
unsigned char* Orig_Image = NULL;
QImage Image;
Orig_Image = new unsigned char[Nb_Lines * Nb_Pixels];
memset(Orig_Image, 0, Nb_Lines * Nb_Pixels);

// create a B/W color table for the image
QVector<QRgb> colorTable;
for (int i = 0; i < 256; i++)
colorTable.push_back(QColor(i, i, i).rgb());


.... edit the data array here

Image = QImage(Orig_Image,Nb_Pixels,Nb_Lines,Nb_Pixels,QIm age::Format_Indexed8);
Image.setColorTable(colorTable);

if(!Image.isNull()) Image.save(QFileDialog::getSaveFileName(this, "Load a picture or file", QString(), "BMP"));

delete(Orig_Image);




Any clues are appreciated! :)

Rhayader
16th March 2011, 18:05
from the qt docs http://doc.qt.nokia.com/4.7-snapshot/qimage.html
"Warning: Painting on a QImage with the format QImage::Format_Indexed8 is not supported."

cdlaweed
16th March 2011, 18:26
hum ok... so there is no possibilities to save a 8bits bmp picture with Qt?

cdlaweed
17th March 2011, 09:20
It is strange because on the doc it is also written:
BMP Windows Bitmap Read/write

if there is no solution on Qt is it possible whit another library?