3030import org .eclipse .swt .graphics .GC ;
3131import org .eclipse .swt .graphics .Image ;
3232import org .eclipse .swt .graphics .ImageData ;
33- import org .eclipse .swt .graphics .ImageDataProvider ;
3433import org .eclipse .swt .graphics .Point ;
3534import org .eclipse .swt .graphics .Rectangle ;
3635import 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
9865public 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