public static BufferedImage prepareImage( String format, int width, int height, boolean transparent, Color bgColor ) {
if ( format.equals( "image/png; mode=8bit" ) || format.equals( "image/png; subtype=8bit" )
|| format.equals( "image/gif" ) ) {
ColorModel cm = PlanarImage.getDefaultColorModel( TYPE_BYTE, 4 );
return new BufferedImage( cm, createBandedRaster( TYPE_BYTE, width, height, 4, null ), false, null );
}
BufferedImage img = new BufferedImage( width, height, getType( transparent, format ) );
if ( !isTransparentAndTransparencySupported( format, transparent ) ) {
Graphics2D g = img.createGraphics();
g.setBackground( bgColor );
g.clearRect( 0, 0, width, height );
g.dispose();
}
return img;
}