You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add option to create transparent Image with alpha channel when using ImageGcDrawer [Multi-Monitor][HiDPI] #2046
Problem
When creating an image using the new ImageGcDrawer, the image is currently initialized as opaque white image (at least on Windows) and it is not possible to create an image with alpha transparency.
Or have I overlooked something?
Request
This requests a possibility to create an image using an ImageGcDrawer comparable to this classic code:
var imageData = new ImageData(width, height, 24, new PaletteData(0xff0000, 0x00ff00, 0x0000ff));
imageData.setAlpha(0, 0, 0);
var image = new Image(display, imageData);
GC gc = new GC(image);
Additional context
This is e.g. required for a multi-monitor/HiDPI compatible solution of issue #501 (draw a mark over an existing icon while preserving its transparency).
That one allows to define a transparency color, so you could initialize the image with that exact color to make everything transparent that is not explicitly drawn.
Otherwise, do you have a complete snippet what you would like to do? If I am not mistaken, the line imageData.setAlpha(0, 0, 0); will only set an alpha value for pixel (0,0), so I have to admit that I do not understand how that is supposed to work.
Yes, I know the TransparencyColorImageGcDrawer, IMHO this is only a limited workaround, not a solution.
If I am not mistaken, the line imageData.setAlpha(0, 0, 0); will only set an alpha value for pixel (0,0), so I have to admit that I do not understand how that is supposed to work.
No, calling imageData.setAlpha the first time initializes the alpha channel with 0 for all pixels.
What if you just call gc.setAlpha(0) as the first operation of the drawer?
The function does what it should do, it sets the transparency for the drawing operations executed afterwards. But a call of setAlpha does not change the current image.
Activity
HeikoKlare commentedon Apr 24, 2025
Did you already see the
TransparencyColorImageGcDrawer? https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/bundles/org.eclipse.swt/Eclipse%20SWT/common/org/eclipse/swt/internal/TransparencyColorImageGcDrawer.javaThat one allows to define a transparency color, so you could initialize the image with that exact color to make everything transparent that is not explicitly drawn.
Otherwise, do you have a complete snippet what you would like to do? If I am not mistaken, the line
imageData.setAlpha(0, 0, 0);will only set an alpha value for pixel (0,0), so I have to admit that I do not understand how that is supposed to work.wahlbrink commentedon Apr 24, 2025
Yes, I know the
TransparencyColorImageGcDrawer, IMHO this is only a limited workaround, not a solution.No, calling
imageData.setAlphathe first time initializes the alpha channel with 0 for all pixels.HeikoKlare commentedon Apr 24, 2025
Okay, I see, thanks for the clarification. It's kind of hack by relying on the implicit initialization of the created array with zeros.
What if you just call
gc.setAlpha(0)as the first operation of the drawer? Doesn't that work either?wahlbrink commentedon Apr 27, 2025
The function does what it should do, it sets the transparency for the drawing operations executed afterwards. But a call of
setAlphadoes not change the current image.HeikoKlare commentedon May 5, 2025
@wahlbrink can you please check whether using GC style
SWT.Transparentin theImageGcDrawersolves the issue for you, as introduced with #2073?wahlbrink commentedon May 10, 2025
Yes, the new option works.
HeikoKlare commentedon May 10, 2025
Great, thank you for the feedback! Thus closing this a resolved.