Qt World Summit: Submit your Presentation

[Solved] double setAlphaChannel

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

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


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

  • 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?

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

  • Remember that setAlphaChannel is deprecated in 4.6

Log in to reply