private static BufferedImage createSolid ( BufferedImage pOriginal , Color pBackground ) { // Create a temporary image of same dimension and type BufferedImage solid = new BufferedImage ( pOriginal . getColorModel ( ) , pOriginal . copyData ( null ) , pOriginal . isAlphaPremultiplied ( ) , null ) ; Graphics2D g = solid . createGraphics ( ) ; try { // Clear in background color g . setColor ( pBackground ) ; g . setComposite ( AlphaComposite . DstOver ) ; // Paint "underneath" g . fillRect ( 0 , 0 , pOriginal . getWidth ( ) , pOriginal . getHeight ( ) ) ; } finally { g . dispose ( ) ; } return solid ; }
Creates a copy of the given image with a solid background