public static BufferedImage createIcon ( IconRow icon , float scale , IconCache iconCache ) { BufferedImage iconImage = null ; if ( icon != null ) { if ( iconCache != null ) { iconImage = iconCache . get ( icon . getId ( ) ) ; } if ( iconImage == null ) { try { iconImage = icon . getDataImage ( ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to get the Icon Row image. Id: " + icon . getId ( ) + ", Name: " + icon . getName ( ) , e ) ; } int dataWidth = iconImage . getWidth ( ) ; int dataHeight = iconImage . getHeight ( ) ; Double iconWidth = icon . getWidth ( ) ; Double iconHeight = icon . getHeight ( ) ; boolean scaleImage = iconWidth != null || iconHeight != null ; if ( ! scaleImage && scale != 1.0f ) { iconWidth = ( double ) dataWidth ; iconHeight = ( double ) dataHeight ; scaleImage = true ; } if ( scaleImage ) { if ( iconWidth == null ) { iconWidth = dataWidth * ( iconHeight / dataHeight ) ; } else if ( iconHeight == null ) { iconHeight = dataHeight * ( iconWidth / dataWidth ) ; } int scaledWidth = Math . round ( scale * iconWidth . floatValue ( ) ) ; int scaledHeight = Math . round ( scale * iconHeight . floatValue ( ) ) ; if ( scaledWidth != dataWidth || scaledHeight != dataHeight ) { Image scaledImage = iconImage . getScaledInstance ( scaledWidth , scaledHeight , Image . SCALE_SMOOTH ) ; iconImage = new BufferedImage ( scaledWidth , scaledHeight , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D graphics = iconImage . createGraphics ( ) ; graphics . drawImage ( scaledImage , 0 , 0 , null ) ; graphics . dispose ( ) ; } } if ( iconCache != null ) { iconCache . put ( icon . getId ( ) , iconImage ) ; } } } return iconImage ; }
Create or retrieve from cache an icon image for the icon row