PDA

View Full Version : Saving Pimap to Bitmap



dbrmik
24th November 2008, 13:02
Hi

I am creating a QPixmap from a QImage and saving as a bitmap using the code below. It works fine apart from the file size 6145Kb, I was expectinmg about 2048 plus a little bit for the header. It seems as though it is not storing the pixel data as 8bit.

uchar *buff=new uchar[2048*1024];
QImage imgt(2048,1024,QImage::Format_Indexed8);

//load image data

QPixmap qpt=QPixmap::fromImage(imgt);
QLabel *qptlabel = new QLabel;
qptlabel->setPixmap(qpt);
qptlabel->show();

//save file
QString filename("test.bmp");
qpt.save(filename,"BMP");

I have tried using QBitmap instead on QPixmap but this gives only black and white image

Any ideas were I am going wrong?

Best Regards

high_flyer
25th November 2008, 09:50
You are correct:

QPixmap QPixmap::fromImage ( const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor ) [static]

Converts the given image to a pixmap using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options.

In case of monochrome and 8-bit images, the image is first converted to a 32-bit pixmap and then filled with the colors in the color table. If this is too expensive an operation, you can use QBitmap::fromImage() instead.

dbrmik
25th November 2008, 23:02
Am I correct in assmuming that Qt will only save as 32 bits per pixel for color bitmaps, it just seems a waste of space. I want to save this as a lossles image. Is there anyway around this problem?

Thanks

high_flyer
26th November 2008, 13:34
You might want to have a look at QImage and QImageWriter .
If none of these classes will help you, you might need to implement the image saving yourself.