question: public EncodedImage scaledEncoded ( int width , int height ) { if ( width == getWidth ( ) && height == getHeight ( ) ) { return this ; } if ( width < 0 ) { float ratio = ( ( float ) height ) / ( ( float ) getHeight ( ) ) ; width = Math . max ( 1 , ( int ) ( getWidth ( ) * ratio ) ) ; } else { if ( height < 0 ) { float ratio = ( ( float ) width ) / ( ( float ) getWidth ( ) ) ; height = Math . max ( 1 , ( int ) ( getHeight ( ) * ratio ) ) ; } } try { ImageIO io = ImageIO . getImageIO ( ) ; if ( io != null ) { String format = ImageIO . FORMAT_PNG ; if ( isOpaque ( ) || ! io . isFormatSupported ( ImageIO . FORMAT_PNG ) ) { if ( io . isFormatSupported ( ImageIO . FORMAT_JPEG ) ) { format = ImageIO . FORMAT_JPEG ; } } if ( io . isFormatSupported ( format ) ) { ByteArrayOutputStream bo = new ByteArrayOutputStream ( ) ; io . save ( new ByteArrayInputStream ( getImageData ( ) ) , bo , format , width , height , 0.9f ) ; Util . cleanup ( bo ) ; EncodedImage img = EncodedImage . create ( bo . toByteArray ( ) ) ; img . opaque = opaque ; img . opaqueChecked = opaqueChecked ; if ( width > - 1 && height > - 1 ) { img . width = width ; img . height = height ; } return img ; } } } catch ( IOException err ) { err . printStackTrace ( ) ; } return null ; }
target:  Performs scaling using ImageIO to generate an encoded Image