Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Convert image

    General and Desktop
    2
    3
    220
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Roy44
      Roy44 last edited by

      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.)

      1 Reply Last reply Reply Quote 0
      • V
        VRonin last edited by VRonin

        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);
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 3
        • Roy44
          Roy44 last edited by

          I works,
          Thanks.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post