@@ -986,30 +986,39 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
986
986
if (image .isDisposed ()) SWT .error (SWT .ERROR_INVALID_ARGUMENT );
987
987
988
988
int imageZoom = getZoom ();
989
- Rectangle src = DPIUtil .scaleUp (drawable , new Rectangle (srcX , srcY , srcWidth , srcHeight ), imageZoom );
990
- Rectangle dest = DPIUtil .scaleUp (drawable , new Rectangle (destX , destY , destWidth , destHeight ), imageZoom );
991
- if (imageZoom != 100 ) {
992
- /*
993
- * This is a HACK! Due to rounding errors at fractional scale factors,
994
- * the coordinates may be slightly off. The workaround is to restrict
995
- * coordinates to the allowed bounds.
996
- */
997
- Rectangle b = image .getBounds (imageZoom );
998
- int errX = src .x + src .width - b .width ;
999
- int errY = src .y + src .height - b .height ;
1000
- if (errX != 0 || errY != 0 ) {
1001
- if (errX <= imageZoom / 100 && errY <= imageZoom / 100 ) {
1002
- src .intersect (b );
1003
- } else {
1004
- SWT .error (SWT .ERROR_INVALID_ARGUMENT );
989
+ float imageScaleFactor = 1f *destWidth /srcWidth ;
990
+ int scaledImageZoom = Math .round (imageZoom *imageScaleFactor );
991
+
992
+ image .applyUsingAnyHandle (scaledImageZoom , (imageHandle ) -> {
993
+ Rectangle src = DPIUtil .scaleUp (drawable , new Rectangle (srcX , srcY , srcWidth , srcHeight ), scaledImageZoom );
994
+ Rectangle dest = DPIUtil .scaleUp (drawable , new Rectangle (destX , destY , destWidth , destHeight ), imageZoom );
995
+
996
+ if (scaledImageZoom != 100 ) {
997
+ /*
998
+ * This is a HACK! Due to rounding errors at fractional scale factors,
999
+ * the coordinates may be slightly off. The workaround is to restrict
1000
+ * coordinates to the allowed bounds.
1001
+ */
1002
+ Rectangle b = image .getBounds (scaledImageZoom );
1003
+ int errX = src .x + src .width - b .width ;
1004
+ int errY = src .y + src .height - b .height ;
1005
+ if (errX != 0 || errY != 0 ) {
1006
+ if (errX <= scaledImageZoom / 100 && errY <= scaledImageZoom / 100 ) {
1007
+ src .intersect (b );
1008
+ } else {
1009
+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
1010
+ }
1005
1011
}
1006
1012
}
1007
- }
1008
- drawImage ( image , src . x , src . y , src . width , src . height , dest . x , dest . y , dest . width , dest . height , false );
1013
+ drawImage ( image , src . x , src . y , src . width , src . height , dest . x , dest . y , dest . width , dest . height , false , scaledImageZoom );
1014
+ } );
1009
1015
}
1010
1016
1011
1017
void drawImage (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1012
- int imageZoom = getZoom ();
1018
+ drawImage (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple , getZoom ());
1019
+ }
1020
+
1021
+ void drawImage (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple , int imageZoom ) {
1013
1022
if (data .gdipGraphics != 0 ) {
1014
1023
//TODO - cache bitmap
1015
1024
long [] gdipImage = srcImage .createGdipImage (imageZoom );
0 commit comments