⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

How to convert 24 bit bmp RGB888 to 16 bit bmp RGB565 ?

  • Hi All,

    As the title says.. I like to convert a 24bit bmp to 16bit bmp...
    When i use the following code

    QImage myImage(2x2_24.bmp);
    QImage *myImageNew = new QImage(myImage.convertToFormat(QImage::Format_RGB16,Qt::AutoColor));

    The image is still a 24bit bmp !!!!
    Any ideas ?

    I'm using qt4.8 and mingw


  • Hi zanes,

    IMO, you have successfully converted it from RGB24 to RGB16.

    Perhaps the member function
    uchar * QImage::bits ()
    can be used to verify the case.

    The problem is that, when you try to save it using .bmp format, it will be converted to RGB32.

    bool QBmpHandler::write(const QImage &img)
    QImage image;
    switch (img.format()) {
    case QImage::Format_ARGB8565_Premultiplied:
    case QImage::Format_ARGB8555_Premultiplied:
    case QImage::Format_ARGB6666_Premultiplied:
    case QImage::Format_ARGB4444_Premultiplied:
    image = img.convertToFormat(QImage::Format_ARGB32);
    case QImage::Format_RGB16:
    case QImage::Format_RGB888:
    case QImage::Format_RGB666:
    case QImage::Format_RGB555:
    case QImage::Format_RGB444:
    image = img.convertToFormat(QImage::Format_RGB32);
    image = img;


  • ahh I see..
    Thank you for your reply Debao...

    So now.. how do I save the file in 16bit bmp ?
    or dump the QImage to a QByteArray ?

    Thank you...

  • i would like to save QImage to a RGB 565 file, dont know how.
    Any Ideas?

Log in to reply