Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138563

QImage::fromHBITMAP does not respect alpha

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.8.6
    • Image formats
    • None
    • Windows

    Description

      We are currently in the transition of Qt5 to Qt6.

      At some code, we were using the following construct:

      image = QtWin::imageFromHBITMAP(m_context, m_bitmap, m_bitmapSize.width(), m_bitmapSize.height()); 

      This was working fine with Qt5. Even for images with alpha values.

      With Qt6, this has been deprecated, so we tried to use the proposed alternative:

      image = QImage::fromHBITMAP(m_bitmap);
      // the image might have alpha values so we reinterpret it per the qt docs
      image.reinterpretAsFormat(QImage::Format_ARGB32) 

      However, when the image is then rendered, it appears that the alpha values are not respected at all (black background instead of transparency).

      See the attached example file as png with proper transparency. Also use the attached minimal reproducible example (which works differently than our use case but looks like the issue is visible there as well)

       

      Attachments

        1. QTBUG-138563.zip
          2 kB
          Malte Hölscher
        2. example.png
          0.3 kB
          Malte Hölscher
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            mlthlschr Malte Hölscher
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes