Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Convert image



  • Hi,

    I would like to convert an image from format Format_ARGB32_Premultiplied to Format_RGB888 with white background
    but the background goes black.

    I try something like :

    QPainter painter;
    painter.begin(&imgRet);
    painter.setBackgroundMode(Qt::OpaqueMode);
    painter.setBackground(Qt::white);
    painter.drawImage(0,0 , image);
    painter.end();
    

    but the background is gray.
    How can I do this ?
    thanks.

    (Sorry for my english.)



  • There's probably a better way but you can use:

    // QImage imgRet;
    for(int i=0,maxW=imgRet.width();i<maxW;++i){
    for(int j=0,maxH=imgRet.height();j<maxH;++j){
    if(qAlpha(imgRet.pixel(i,j))<0xff)
    imgRet.setPixel(i,j,qRgba(0xff,0xff,0xff,0xff));
    }
    }
    imgRet=imgRet.convertToFormat(QImage::Format_RGB888);
    


  • I works,
    Thanks.


Log in to reply