@@ -351,28 +351,33 @@ public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType
351351
352352 // use a transparent background if the image type supports alpha
353353 Graphics2D g = image .createGraphics ();
354- if ( image . getType () == BufferedImage . TYPE_INT_ARGB )
354+ try
355355 {
356- g .setBackground (new Color (0 , 0 , 0 , 0 ));
356+ if (image .getType () == BufferedImage .TYPE_INT_ARGB )
357+ {
358+ g .setBackground (new Color (0 , 0 , 0 , 0 ));
359+ }
360+ else
361+ {
362+ g .setBackground (Color .WHITE );
363+ }
364+ g .clearRect (0 , 0 , image .getWidth (), image .getHeight ());
365+
366+ transform (g , page .getRotation (), cropBox , scale , scale );
367+
368+ // the end-user may provide a custom PageDrawer
369+ RenderingHints actualRenderingHints =
370+ renderingHints == null ? createDefaultRenderingHints (g ) : renderingHints ;
371+ PageDrawerParameters parameters =
372+ new PageDrawerParameters (this , page , subsamplingAllowed , destination ,
373+ actualRenderingHints , imageDownscalingOptimizationThreshold );
374+ PageDrawer drawer = createPageDrawer (parameters );
375+ drawer .drawPage (g , cropBox );
357376 }
358- else
377+ finally
359378 {
360- g .setBackground ( Color . WHITE );
379+ g .dispose ( );
361380 }
362- g .clearRect (0 , 0 , image .getWidth (), image .getHeight ());
363-
364- transform (g , page .getRotation (), cropBox , scale , scale );
365-
366- // the end-user may provide a custom PageDrawer
367- RenderingHints actualRenderingHints =
368- renderingHints == null ? createDefaultRenderingHints (g ) : renderingHints ;
369- PageDrawerParameters parameters =
370- new PageDrawerParameters (this , page , subsamplingAllowed , destination ,
371- actualRenderingHints , imageDownscalingOptimizationThreshold );
372- PageDrawer drawer = createPageDrawer (parameters );
373- drawer .drawPage (g , cropBox );
374-
375- g .dispose ();
376381
377382 if (image .getType () != imageType .toBufferedImageType ())
378383 {
0 commit comments