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. [Solved] double setAlphaChannel
Forum Updated to NodeBB v4.3 + New Features

[Solved] double setAlphaChannel

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.5k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kbatalov
    wrote on last edited by
    #1

    Hi all,

    After second call of setAlphaChannel function image contains wrong alpha channel value.

    Please find below small piece of code for more understanding:

    @
    QImage alphaMap(image.width(), image.height(), QImage::Format_Indexed8);
    alphaMap.fill(100);

    image.setAlphaChannel(alphaMap);
    
    int _tmp = image.alphaChannel().pixelIndex(0,0);  // _tmp == 100 its ok
    
    alphaMap.fill(150);
    
    image.setAlphaChannel(alphaMap);
    
    _tmp = image.alphaChannel().pixelIndex(0,0);  // _tmp == 59! Why?!?!?
    

    @

    So my question is, what is right way to change existing alpha channel?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on last edited by
      #2

      Since setAlphaChannel definitely changes your pixmap, the value is not wrong. Look:

      Your first value is 100, which is in fact 0.3906 of 256.
      After that you put a new alpha layer with the value of 150, which is 0.585 of 256.

      However, you set an alpha layer to a current transparent area. So your final result will be:
      0.585 * 0.3906 * 256 = ~59. Got it?

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kbatalov
        wrote on last edited by
        #3

        Got it! I had to guess that alpha value is accumulated.
        Thanks a lot!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          danilocesar
          wrote on last edited by
          #4

          Remember that setAlphaChannel is deprecated in 4.6

          <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
          Software Engineer

          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