public static BufferedImage get ( Image img , int imgType ) { Function < Integer , ImageObserver > obs = flags -> { return ( image , infoflags , x , y , width , height ) -> ( infoflags & flags ) != flags ; } ; BufferedImage bimg = new BufferedImage ( img . getWidth ( obs . apply ( ImageObserver . WIDTH ) ) , img . getHeight ( obs . apply ( ImageObserver . HEIGHT ) ) , imgType ) ; Graphics2D gr2D = bimg . createGraphics ( ) ; gr2D . drawImage ( img , 0 , 0 , obs . apply ( ImageObserver . ALLBITS ) ) ; gr2D . dispose ( ) ; return bimg ; }
Creates a new BufferedImage of the specified imgType and same size as the provided image and draws the provided Image onto the new BufferedImage .