Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert image
Forum Updated to NodeBB v4.3 + New Features

Convert image

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 386 Views
  • 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.
  • Roy44R Offline
    Roy44R Offline
    Roy44
    wrote on last edited by
    #1

    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
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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
      3
      • Roy44R Offline
        Roy44R Offline
        Roy44
        wrote on last edited by
        #3

        I works,
        Thanks.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved