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. Opacity of a QImage becomes black
QtWS25 Last Chance

Opacity of a QImage becomes black

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 608 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.
  • T Offline
    T Offline
    timain
    wrote on last edited by
    #1

    Hello,

    I want to set opacity of my image, when I save it (PNG or JPEG), transparent image becomes black/dark image
    Someone could help me? ( I used ARGB32 format )

    Thank you.

    1 Reply Last reply
    0
    • BondrusiekB Offline
      BondrusiekB Offline
      Bondrusiek
      wrote on last edited by
      #2

      I have the same problem. Code without set opacity

                  QImage image = m_GemsPixmap.copy(p.kind*49, 0, 49, 49).toImage().convertToFormat(QImage::Format_ARGB32);
                  //            for (int x(0); x != image.width(); ++x)
                  //            {
                  //              for (int y(0); y != image.height(); ++y)
                  //              {
                  //                QColor color(image.pixel(x,y));
                  //                color.setAlpha(p.alpha);
                  //                image.setPixel(x, y, color.rgba());
                  //              }
                  //            }
                  m_pixmapItems[i][j].setPixmap(QPixmap::fromImage(image));
      

      Result
      screen0.png
      Code with control opacicty.

                  QImage image = m_GemsPixmap.copy(p.kind*49, 0, 49, 49).toImage().convertToFormat(QImage::Format_ARGB32);
                  for (int x(0); x != image.width(); ++x)
                  {
                      for (int y(0); y != image.height(); ++y)
                      {
                          QColor color(image.pixel(x,y));
                          color.setAlpha(p.alpha);
                          image.setPixel(x, y, color.rgba());
                      }
                  }
                  m_pixmapItems[i][j].setPixmap(QPixmap::fromImage(image));
      

      Result:
      screen1.png
      Transparent area is always black but for other opacity work correctly.
      Do you know how solve that?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Do you mean that you need alpha to be at least 1 in order to have proper transparency handling ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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