112112 * @see WritableRaster
113113 */
114114
115- public class BufferedImage extends Image implements RenderedImage , Transparency // , WritableRenderedImage
115+ public class BufferedImage extends Image implements RenderedImage , Transparency , ImageObserver
116+ // , WritableRenderedImage
116117{
117118
118119 private static final int STATE_UNINITIALIZED = 0 ;
@@ -1366,7 +1367,7 @@ public Graphics2D createGraphics() {
13661367 // allow creating a Graphics from MemoryImageSource
13671368 // so pixels would never be there.
13681369 if (秘pix != null )
1369- 秘g .drawImageFromPixelsOrRaster (this , 0 , 0 , null );
1370+ 秘g .drawImageFromPixelsOrRaster (this , 0 , 0 , ( ImageObserver ) this );
13701371 }
13711372 Object pix = 秘pix ;
13721373 /**
@@ -1389,8 +1390,11 @@ public Graphics2D createGraphics() {
13891390 }
13901391
13911392 public void 秘graphicsDisposed () {
1392- gCount = Math . max ( 0 , gCount - 1 );
1393+ boolean doSync = ( 秘haveCanvas () && 秘isRasterDirty ( false ) );
13931394 秘state = STATE_GRAPHICS ;
1395+ if (doSync ) {
1396+ 秘syncRaster ();
1397+ }
13941398 }
13951399
13961400 /**
@@ -1404,20 +1408,25 @@ public Graphics2D createGraphics() {
14041408 */
14051409 @ Override
14061410 public void flush () {
1407- boolean isStolen = 秘isRasterDirty (false );
1408- boolean haveRaster = 秘haveRaster ();
1409- if (isStolen && !haveRaster )
1410- 秘ensureRasterUpToDate (); // will set STATE_RASTER
1411+ boolean setRasterState = 秘syncRaster ();
14111412 if (秘haveRaster () && 秘pix == null ) {
14121413 秘getPixelsFromRaster (0 );
14131414 }
14141415 秘getImageGraphic ();
1415- if (isStolen || haveRaster )
1416+ if (setRasterState )
14161417 秘state |= STATE_RASTER ;
1417- while (gCount > 0 && -- gCount >= 0 )
1418+ while (gCount -- > 0 )
14181419 秘g .dispose ();
14191420 }
14201421
1422+ private boolean 秘syncRaster () {
1423+ boolean isStolen = 秘isRasterDirty (false );
1424+ boolean haveRaster = 秘haveRaster ();
1425+ if (isStolen && !haveRaster )
1426+ 秘ensureRasterUpToDate (); // will set STATE_RASTER
1427+ return (isStolen || haveRaster );
1428+ }
1429+
14211430 /**
14221431 * Called only in JavaScript, because we are using this in HTML5Canvas, which is
14231432 * a distributed public interface, and the Mandarin char was causing problems.
@@ -2474,4 +2483,10 @@ public String toString() {
24742483 return new Color (pc .pixelToRgb (pc .rgbToPixel (c .getRGB (), null ), null ));
24752484 }
24762485
2486+ @ Override
2487+ public boolean imageUpdate (Image img , int infoflags , int x , int y , int width , int height ) {
2488+ // ignored
2489+ return false ;
2490+ }
2491+
24772492}
0 commit comments