Repository navigation
On win32, if GC drawable is not autoscalable GC.drawImage can cut of parts of the image #2504
Description
Describe the bug
GC.drawImage scales the image data but not the image source coordinates if the gc is not autoScalable.
- Use a GC with
gc.drawable.isAutoScalable()==false - Call
gc.drawImage(image, 0, 0, 50, 50, 0, 0, 100, 100);
For this, DrawScalingImageToImageOperation.calculateZoomForImage gives a zoom of 200.
Because the gc drawable is not autoScalable, the image source coordinates are not scaled by 200
eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
Line 1158 in 1094ebd
| Rectangle src = Win32DPIUtils.pointToPixel(drawable, new Rectangle(srcX, srcY, srcWidth, srcHeight), scaledImageZoom); |
Because the image is scaled independent of isAutoScalable, the coordinates get out of sync
eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
Line 1201 in 1094ebd
| long [] gdipImage = srcImage.createGdipImage(imageZoom); |
To Reproduce
A standalone SWT snippet to reproduce the behavior (preferable)
package test.package;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ReproDemo {
static final float targetScale = 2f;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, ReproDemo.class.getResourceAsStream("/50x50.png"));
Rectangle bounds = image.getBounds();
shell.setLayout(new FormLayout());
Canvas canvas = new Canvas(shell, 0) {
@Override
public boolean isAutoScalable() {
return false;
}
};
FormData formData = new FormData();
formData.left = new FormAttachment(0,0);
formData.top = new FormAttachment(0,0);
formData.width = Math.round(bounds.width * targetScale);
formData.height = Math.round(bounds.height * targetScale);
canvas.setLayoutData(formData);
canvas.addPaintListener(e -> {
e.gc.drawImage(image, 0, 0, bounds.width, bounds.height, 0, 0, formData.width, formData.height);
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
image.dispose();
display.dispose();
}
}
Expected behavior
The given source coordinates and the source image are scaled in the same way
Screenshots
If applicable, add screenshots to help explain your problem.
With source and destination at 1:1:

With source and destination at 1:2:

Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc)
Checked on Win10 and Win11 -
JRE/JDK version
Azul Zulu 21.0.3
Version since
4.37RC2
Activity
HeikoKlare commentedon Sep 12, 2025
Thank you for the report! I can reproduce the issue with the given snippet (just replacing the
50x50.pngwith any image I have at hand). We will have a look at this.Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable
Set zoom for source image as GCzoom when the GC is not autoscalable