protected static BufferedImage createBufferedImage ( int width , int height , boolean hasAlpha ) { BufferedImage bimage = null ; GraphicsEnvironment ge = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) ; try { // Determine the type of transparency of the new buffered image int transparency = Transparency . OPAQUE ; if ( hasAlpha ) { transparency = Transparency . TRANSLUCENT ; } // Create the buffered image GraphicsDevice gs = ge . getDefaultScreenDevice ( ) ; GraphicsConfiguration gc = gs . getDefaultConfiguration ( ) ; bimage = gc . createCompatibleImage ( width , height , transparency ) ; } catch ( HeadlessException e ) { // The system does not have a screen } if ( bimage == null ) { // Create a buffered image using the default color model int type = BufferedImage . TYPE_INT_RGB ; if ( hasAlpha ) { type = BufferedImage . TYPE_INT_ARGB ; } bimage = new BufferedImage ( width , height , type ) ; } return bimage ; }
Create a buffered image of the given width and height compatible with the alpha requirement .