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. How to alpha-blend a color-inverted image on top of another image with QPainter?
Forum Updated to NodeBB v4.3 + New Features

How to alpha-blend a color-inverted image on top of another image with QPainter?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 807 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.
  • K Offline
    K Offline
    Kirinyale
    wrote on last edited by
    #1

    I am drawing an image that consists of two logical "layers" (terrain & objects). When a special mode is active, I want to draw the second layer (objects) with inverted color. Individual objects are translucent and overlapping, so I am first drawing them all with normal alpha-blending (CompositionMode_SourceOver) into an offscreen pixmap. Then I need to invert the color of the result (without touching alpha!) and blend it on top of the destination (terrain).

    I tried using RasterOp_NotSource. Obviously, it doesn't include alpha-blending, so I tried to do it in 2 steps as a workaround (with another temporary pixmap in between). Unfortunately, for some reason RasterOp_NotSource destroys my alpha by setting it all to 0xFF regardless of what it was, so that doesn't work either.

    So how can I achieve what I need?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kirinyale
      wrote on last edited by
      #2

      Update: I've found QImage::invertPixels() which seems to do what I want (and the result can then be blended as normally). Not sure yet if this is the best solution in terms of performance, but at least it works. :)

      1 Reply Last reply
      2

      • Login

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