@@ -98,6 +98,11 @@ public final class Image extends Resource implements Drawable {
9898 */
9999 private boolean isInitialized ;
100100
101+ /**
102+ * this field is used to mark destroyed images
103+ */
104+ private boolean isDestroyed ;
105+
101106 /**
102107 * specifies the transparent pixel
103108 */
@@ -521,7 +526,7 @@ public Image (Device device, String filename) {
521526 }
522527 return null ;
523528 });
524- if (imageProvider .getImageData (100 ) == null ) {
529+ if (imageProvider .newImageData (100 ) == null ) {
525530 SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
526531 ": [" + filename + "] returns null ImageData at 100% zoom." );
527532 }
@@ -562,7 +567,7 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
562567 super (device );
563568 this .imageProvider = new ImageFileNameProviderWrapper (imageFileNameProvider );
564569 initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
565- if (imageProvider .getImageData (100 ) == null ) {
570+ if (imageProvider .newImageData (100 ) == null ) {
566571 SWT .error (SWT .ERROR_INVALID_ARGUMENT , null ,
567572 ": ImageFileNameProvider [" + imageFileNameProvider + "] returns null ImageData at 100% zoom." );
568573 }
@@ -1003,7 +1008,7 @@ public static void drawScaled(GC gc, Image original, int width, int height, floa
10031008void destroy () {
10041009 device .deregisterResourceWithZoomSupport (this );
10051010 if (memGC != null ) memGC .dispose ();
1006- this .imageProvider . destroy () ;
1011+ this .isDestroyed = true ;
10071012 destroyHandle ();
10081013 memGC = null ;
10091014}
@@ -1229,7 +1234,10 @@ public ImageData getImageData() {
12291234 */
12301235public ImageData getImageData (int zoom ) {
12311236 if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
1232- return imageProvider .getImageData (zoom );
1237+ if (zoomLevelToImageHandle .containsKey (zoom )) {
1238+ return zoomLevelToImageHandle .get (zoom ).getImageData ();
1239+ }
1240+ return this .imageProvider .newImageData (zoom );
12331241}
12341242
12351243
@@ -1766,7 +1774,7 @@ public void internal_dispose_GC (long hDC, GCData data) {
17661774 */
17671775@ Override
17681776public boolean isDisposed () {
1769- return this . imageProvider . isDisposed () ;
1777+ return ! isInitialized || isDestroyed ;
17701778}
17711779
17721780/**
@@ -1850,17 +1858,9 @@ public static Image win32_new(Device device, int type, long handle, int nativeZo
18501858}
18511859
18521860private abstract class AbstractImageProviderWrapper {
1853- private boolean isDestroyed ;
18541861
18551862 protected abstract Rectangle getBounds (int zoom );
18561863
1857- protected final ImageData getImageData (int zoom ) {
1858- if (zoomLevelToImageHandle .containsKey (zoom )) {
1859- return zoomLevelToImageHandle .get (zoom ).getImageData ();
1860- }
1861- return newImageData (zoom );
1862- }
1863-
18641864 abstract ImageData newImageData (int zoom );
18651865
18661866 abstract AbstractImageProviderWrapper createCopy (Image image );
@@ -1892,14 +1892,6 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) {
18921892 return init (data , zoom );
18931893 }
18941894 }
1895-
1896- protected boolean isDisposed () {
1897- return !isInitialized || isDestroyed ;
1898- }
1899-
1900- protected void destroy () {
1901- this .isDestroyed = true ;
1902- }
19031895}
19041896
19051897private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
@@ -1944,7 +1936,7 @@ private abstract class ImageFromImageDataProviderWrapper extends AbstractImagePr
19441936 void initImage () {
19451937 // As the init call configured some Image attributes (e.g. type)
19461938 // it must be called
1947- getImageData (100 );
1939+ newImageData (100 );
19481940 }
19491941
19501942 @ Override
0 commit comments