Results 1 to 4 of 4

Thread: Saving Pimap to Bitmap

  1. #1
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Saving Pimap to Bitmap

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Saving Pimap to Bitmap

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    dbrmik (25th November 2008)

  4. #3
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving Pimap to Bitmap

    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

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Saving Pimap to Bitmap

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.