Skip to content

Commit 865ba62

Browse files
committed
Copy and paste does not try to autoscale the image anymore, the image is always consumed at 100% zoom by copy, while doing the paste the zooms are set to 100
1 parent 8b45dd8 commit 865ba62

File tree

2 files changed

+9
-38
lines changed

2 files changed

+9
-38
lines changed

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/ImageTransfer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.eclipse.swt.*;
1717
import org.eclipse.swt.graphics.*;
18-
import org.eclipse.swt.internal.*;
1918
import org.eclipse.swt.internal.ole.win32.*;
2019
import org.eclipse.swt.internal.win32.*;
2120

@@ -184,8 +183,9 @@ public Object nativeToJava(TransferData transferData) {
184183
pSourceBits -= scanline;
185184
}
186185
}
187-
Image image = Image.win32_new(null, SWT.BITMAP, memDib, DPIUtil.getNativeDeviceZoom());
188-
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
186+
Image image = Image.win32_new(null, SWT.BITMAP, memDib, 100);
187+
188+
ImageData data = image.getImageData (100);
189189
OS.DeleteObject(memDib);
190190
image.dispose();
191191
return data;

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/ClipboardExample.java

+6-35
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.eclipse.swt.graphics.GC;
3131
import org.eclipse.swt.graphics.Image;
3232
import org.eclipse.swt.graphics.ImageData;
33-
import org.eclipse.swt.graphics.ImageDataProvider;
3433
import org.eclipse.swt.graphics.Point;
3534
import org.eclipse.swt.graphics.Rectangle;
3635
import org.eclipse.swt.layout.FillLayout;
@@ -62,38 +61,6 @@ public class ClipboardExample {
6261
Label status;
6362
static final int HSIZE = 100, VSIZE = 60;
6463

65-
static final class AutoScaleImageDataProvider implements ImageDataProvider {
66-
ImageData imageData;
67-
int currentZoom;
68-
public AutoScaleImageDataProvider (ImageData data) {
69-
this.imageData = data;
70-
this.currentZoom = getDeviceZoom ();
71-
}
72-
73-
@Override
74-
public ImageData getImageData (int zoom) {
75-
return autoScaleImageData(imageData, zoom, currentZoom);
76-
}
77-
78-
static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) {
79-
if (imageData == null || targetZoom == currentZoom) return imageData;
80-
float scaleFactor = ((float) targetZoom)/((float) currentZoom);
81-
return imageData.scaledTo (Math.round (imageData.width * scaleFactor), Math.round (imageData.height * scaleFactor));
82-
}
83-
84-
static int getDeviceZoom () {
85-
int zoom = 100;
86-
String value = System.getProperty ("org.eclipse.swt.internal.deviceZoom");
87-
if (value != null) {
88-
try {
89-
zoom = Integer.parseInt(value);
90-
} catch (NumberFormatException e) {
91-
e.printStackTrace();
92-
}
93-
}
94-
return zoom;
95-
}
96-
}
9764

9865
public static void main( String[] args) {
9966
Display display = new Display();
@@ -456,6 +423,8 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
456423
copyImage[0].dispose();
457424
}
458425
copyImage[0] = new Image(e.display, string);
426+
System.out.println("width in open image is " + copyImage[0].getImageData().width);
427+
System.out.println("height in open image is " + copyImage[0].getImageData().height);
459428
copyVBar.setEnabled(true);
460429
copyHBar.setEnabled(true);
461430
copyOrigin.x = 0; copyOrigin.y = 0;
@@ -477,7 +446,7 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
477446
if (copyImage[0] != null) {
478447
status.setText("");
479448
// Fetch ImageData at current zoom and save in the clip-board.
480-
clipboard.setContents(new Object[] {copyImage[0].getImageDataAtCurrentZoom()}, new Transfer[] {ImageTransfer.getInstance()});
449+
clipboard.setContents(new Object[] {copyImage[0].getImageData()}, new Transfer[] {ImageTransfer.getInstance()});
481450
} else {
482451
status.setText("No image to copy");
483452
}
@@ -541,7 +510,9 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
541510
}
542511
status.setText("");
543512
// Consume the ImageData at current zoom as-is.
544-
pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
513+
pasteImage[0] = new Image(e.display, imageData);
514+
System.out.println("width is " + imageData.width);
515+
System.out.println("height is " + imageData.height);
545516
pasteVBar.setEnabled(true);
546517
pasteHBar.setEnabled(true);
547518
pasteOrigin.x = 0; pasteOrigin.y = 0;

0 commit comments

Comments
 (0)