Search code examples
javadrawingswtjava-canvas

How can I draw a semi transparent coloured mask over an already drawn to SWT canvas?


so I'd like to draw a coloured (red) area over the top of an existing canvas drawing, like a red tinted lens being placed over it, so the original image is still visible underneath.

The problem is that I am extending a canvas that draws it's own image and I am drawing over the top of it.

How can I do this?


Solution

  • In your Canvas paint() method,

    1. draw image
    2. gc.setAlpha(100) //decide your value
    3. gc.fillRectangle(rect) //rect is client area of the canvas

    I believe you should get what you are looking for.