30
30
import org .eclipse .swt .graphics .GC ;
31
31
import org .eclipse .swt .graphics .Image ;
32
32
import org .eclipse .swt .graphics .ImageData ;
33
- import org .eclipse .swt .graphics .ImageDataProvider ;
34
33
import org .eclipse .swt .graphics .Point ;
35
34
import org .eclipse .swt .graphics .Rectangle ;
36
35
import org .eclipse .swt .layout .FillLayout ;
@@ -62,38 +61,6 @@ public class ClipboardExample {
62
61
Label status ;
63
62
static final int HSIZE = 100 , VSIZE = 60 ;
64
63
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
- }
97
64
98
65
public static void main ( String [] args ) {
99
66
Display display = new Display ();
@@ -456,6 +423,8 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
456
423
copyImage [0 ].dispose ();
457
424
}
458
425
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 );
459
428
copyVBar .setEnabled (true );
460
429
copyHBar .setEnabled (true );
461
430
copyOrigin .x = 0 ; copyOrigin .y = 0 ;
@@ -477,7 +446,7 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
477
446
if (copyImage [0 ] != null ) {
478
447
status .setText ("" );
479
448
// 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 ()});
481
450
} else {
482
451
status .setText ("No image to copy" );
483
452
}
@@ -541,7 +510,9 @@ void createImageTransfer(Composite copyParent, Composite pasteParent){
541
510
}
542
511
status .setText ("" );
543
512
// 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 );
545
516
pasteVBar .setEnabled (true );
546
517
pasteHBar .setEnabled (true );
547
518
pasteOrigin .x = 0 ; pasteOrigin .y = 0 ;
0 commit comments