There is a SWT error that happens on Linux with x2 scaling when trying to draw a grayed image with GC#drawImage method that allows image scaling. Regular non-grayed image drawing works as expected. Also this problem doesn't happen on non-scaled desktop.
The error is:
Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid
at org.eclipse.swt.SWT.error(SWT.java:4903)
at org.eclipse.swt.SWT.error(SWT.java:4837)
at org.eclipse.swt.SWT.error(SWT.java:4808)
at org.eclipse.swt.graphics.GC.drawImage(GC.java:876)
at org.eclipse.swt.graphics.GC.drawImage(GC.java:859)
at org.eclipse.swt.snippets.DerivedImageScaledPaintBug.lambda$0(DerivedImageScaledPaintBug.java:24)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5857)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1617)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1643)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1626)
at org.eclipse.swt.widgets.Control.gtk_draw(Control.java:3877)
at org.eclipse.swt.widgets.Scrollable.gtk_draw(Scrollable.java:396)
at org.eclipse.swt.widgets.Composite.gtk_draw(Composite.java:506)
at org.eclipse.swt.widgets.Canvas.gtk_draw(Canvas.java:174)
at org.eclipse.swt.widgets.Shell.gtk_draw(Shell.java:1591)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2570)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:6842)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6164)
at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_do_event(Native Method)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1600)
at org.eclipse.swt.internal.gtk3.GTK3.gtk_main_iteration_do(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4516)
at org.eclipse.swt.snippets.DerivedImageScaledPaintBug.main(DerivedImageScaledPaintBug.java:29)
To Reproduce
Here's the SWT snippet to reproduce the error:
package org.eclipse.swt.snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DerivedImageScaledPaintBug {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setText("");
final Image image = display.getSystemImage (SWT.ICON_QUESTION);
final Image grayImage = new Image(display, image, SWT.IMAGE_GRAY);
shell.addListener (SWT.Paint, e -> {
Rectangle rect = image.getBounds ();
int width = rect.width;
int height = rect.height;
GC gc = e.gc;
int x = 10, y = 10;
gc.drawImage (image, x, y);
gc.drawImage(grayImage, 0, 0, width, height, x + width + 10, y, width * 2, height * 2);
});
shell.setSize (600, 400);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
display.dispose ();
}
}
Environment:
- Select the platform(s) on which the behavior is seen:
- Additional OS info (e.g. OS version, Linux Desktop, etc)
Debian 13.
Version since
Tested with all versions since Eclipse 4.34 and the failure was present.
There is a SWT error that happens on Linux with x2 scaling when trying to draw a grayed image with GC#drawImage method that allows image scaling. Regular non-grayed image drawing works as expected. Also this problem doesn't happen on non-scaled desktop.
The error is:
To Reproduce
Here's the SWT snippet to reproduce the error:
Environment:
Debian 13.
Version since
Tested with all versions since Eclipse 4.34 and the failure was present.