diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index c6085e45d9a..dfc5c0ee001 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -1359,10 +1359,10 @@ public ImageData getImageData() { */ public ImageData getImageData (int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - int currentZoom = getZoom(); - if (zoom == currentZoom) { - return getImageDataAtCurrentZoom(); - } else if (imageProvider != null) { + if (zoomLevelToImageHandle.get(zoom) != null) { + return zoomLevelToImageHandle.get(zoom).getImageData(); + } + if (imageProvider != null) { return imageProvider.getImageData(zoom); } @@ -1371,7 +1371,9 @@ public ImageData getImageData (int zoom) { if (memGC != null) { return getImageDataAtCurrentZoom(); } - return DPIUtil.scaleImageData (device, getImageMetadata(currentZoom).getImageData(), zoom, currentZoom); + TreeSet availableZooms = new TreeSet<>(zoomLevelToImageHandle.keySet()); + int closestZoom = Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom)); + return DPIUtil.scaleImageData (device, getImageMetadata(closestZoom).getImageData(), zoom, closestZoom); } /** diff --git a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/ImageWin32Tests.java b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/ImageWin32Tests.java index 5aef1da5c5f..dea3713b5ca 100644 --- a/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/ImageWin32Tests.java +++ b/tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/ImageWin32Tests.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.widgets.Display; @@ -36,6 +37,25 @@ public void setUp() { display = Display.getDefault(); } + @Test + public void testImageDataForDifferentZoomsShouldNotBeScaledToTheAutoScaledZoom() { + Image image = new Image(display, 10, 10); + int zoom1 = 125; + int zoom2 = 150; + ImageData imageDataAtZoom1 = image.getImageData(125); + ImageData imageDataAtZoom2 = image.getImageData(150); + assertNotEquals("ImageData::height should not be the same for imageData at different zoom levels within the same autoScale zoom bounds", imageDataAtZoom1.height, imageDataAtZoom2.height); + assertNotEquals("ImageData::width should not be the same for imageData at different zoom levels within the same autoScale zoom bounds", imageDataAtZoom1.width, imageDataAtZoom2.width); + int correctedZoomForZoom1 = DPIUtil.getZoomForAutoscaleProperty(zoom1); + int correctedZoomForZoom2 = DPIUtil.getZoomForAutoscaleProperty(zoom2); + assertEquals("Zoom1 and Zoom2 should have the same corrected zoom", correctedZoomForZoom1, correctedZoomForZoom2); + ImageData imageDataAtCorrectedZoom = image.getImageData(correctedZoomForZoom1); + assertNotEquals("ImageData::height of imageData at zoom1 should not be the same as that of corrected zoom ", imageDataAtZoom1.height, imageDataAtCorrectedZoom.height); + assertNotEquals("ImageData::width of imageData at zoom1 should not be the same as that of corrected zoom ", imageDataAtZoom1.width, imageDataAtCorrectedZoom.width); + assertNotEquals("ImageData::height of imageData at zoom2 should not be the same as that of corrected zoom ", imageDataAtZoom2.height, imageDataAtCorrectedZoom.height); + assertNotEquals("ImageData::width of imageData at zoom2 should not be the same as that of corrected zoom ", imageDataAtZoom2.width, imageDataAtCorrectedZoom.width); + } + @Test public void testImageShouldHaveDimesionAsPerZoomLevel() { int zoom = DPIUtil.getDeviceZoom();