@@ -326,28 +326,33 @@ public BufferedImage renderImage(int pageIndex, float scale, ImageType imageType
326326
327327 // use a transparent background if the image type supports alpha
328328 Graphics2D g = image .createGraphics ();
329- if ( image . getType () == BufferedImage . TYPE_INT_ARGB )
329+ try
330330 {
331- g .setBackground (new Color (0 , 0 , 0 , 0 ));
331+ if (image .getType () == BufferedImage .TYPE_INT_ARGB )
332+ {
333+ g .setBackground (new Color (0 , 0 , 0 , 0 ));
334+ }
335+ else
336+ {
337+ g .setBackground (Color .WHITE );
338+ }
339+ g .clearRect (0 , 0 , image .getWidth (), image .getHeight ());
340+
341+ transform (g , page .getRotation (), cropBox , scale , scale );
342+
343+ // the end-user may provide a custom PageDrawer
344+ RenderingHints actualRenderingHints
345+ = renderingHints == null ? createDefaultRenderingHints (g ) : renderingHints ;
346+ PageDrawerParameters parameters
347+ = new PageDrawerParameters (this , page , subsamplingAllowed , destination ,
348+ actualRenderingHints , imageDownscalingOptimizationThreshold );
349+ PageDrawer drawer = createPageDrawer (parameters );
350+ drawer .drawPage (g , cropBox );
332351 }
333- else
352+ finally
334353 {
335- g .setBackground ( Color . WHITE );
354+ g .dispose ( );
336355 }
337- g .clearRect (0 , 0 , image .getWidth (), image .getHeight ());
338-
339- transform (g , page .getRotation (), cropBox , scale , scale );
340-
341- // the end-user may provide a custom PageDrawer
342- RenderingHints actualRenderingHints =
343- renderingHints == null ? createDefaultRenderingHints (g ) : renderingHints ;
344- PageDrawerParameters parameters =
345- new PageDrawerParameters (this , page , subsamplingAllowed , destination ,
346- actualRenderingHints , imageDownscalingOptimizationThreshold );
347- PageDrawer drawer = createPageDrawer (parameters );
348- drawer .drawPage (g , cropBox );
349-
350- g .dispose ();
351356
352357 if (image .getType () != imageType .toBufferedImageType ())
353358 {
0 commit comments