/** * @return an empty image conforming to the request parameters */ public static BufferedImage prepareImage( String format, int width, int height, boolean transparent, Color bgColor ) { if ( format.equals( "image/png; mode=8bit" ) || format.equals( "image/png; subtype=8bit" ) || format.equals( "image/gif" ) ) { ColorModel cm = PlanarImage.getDefaultColorModel( TYPE_BYTE, 4 ); return new BufferedImage( cm, createBandedRaster( TYPE_BYTE, width, height, 4, null ), false, null ); } BufferedImage img = new BufferedImage( width, height, getType( transparent, format ) ); if ( !isTransparentAndTransparencySupported( format, transparent ) ) { Graphics2D g = img.createGraphics(); g.setBackground( bgColor ); g.clearRect( 0, 0, width, height ); g.dispose(); } return img; }
@Override public void serializeException( HttpResponseBuffer response, OWSException ex, XMLExceptionSerializer exceptionSerializer, Map<String, String> map ) throws SerializingException { int width = Integer.parseInt( map.get( "WIDTH" ) ); int height = Integer.parseInt( map.get( "HEIGHT" ) ); boolean transparent = map.get( "TRANSPARENT" ) != null && map.get( "TRANSPARENT" ).equalsIgnoreCase( "true" ); String format = map.get( "FORMAT" ); Color color = map.get( "BGCOLOR" ) == null ? white : decode( map.get( "BGCOLOR" ) ); BufferedImage img = prepareImage( format, width, height, transparent, color ); try { controller.sendImage( img, response, format ); } catch ( OWSException e ) { throw new SerializingException( e ); } catch ( IOException e ) { throw new SerializingException( e ); } }
private static int getType( boolean transparent, String format ) { if ( !isTransparentAndTransparencySupported( format, transparent ) ) { return TYPE_INT_RGB; } return transparent ? TYPE_INT_ARGB : TYPE_INT_RGB; }
private BufferedImage buildLegend( GetLegendGraphic req, Legends renderer, Style style, boolean originalSize, HashMap<String, BufferedImage> legendMap ) { BufferedImage img = MapService.prepareImage( req ); Graphics2D g = img.createGraphics(); g.setRenderingHint( KEY_ANTIALIASING, VALUE_ANTIALIAS_ON ); g.setRenderingHint( KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON ); renderer.paintLegend( style, req.getWidth(), req.getHeight(), g ); g.dispose(); if ( req.getFormat().equals( "image/png; mode=8bit" ) || req.getFormat().equals( "image/png; subtype=8bit" ) || req.getFormat().equals( "image/gif" ) ) { img = postprocessPng8bit( img ); } if ( originalSize ) { legendMap.put( req.getFormat(), img ); } return img; }
Color color = map.get( "BGCOLOR" ) == null ? white : decode( map.get( "BGCOLOR" ) ); BufferedImage img = prepareImage( format, width, height, transparent, color ); Graphics2D g = img.createGraphics(); g.setColor( black );
/** * @param req * should be a GetMap or GetLegendGraphic * @return an empty image conforming to the request parameters */ public static BufferedImage prepareImage( Object req ) { String format = null; int width = 0, height = 0; Color bgcolor = null; boolean transparent = false; if ( req instanceof GetLegendGraphic ) { GetLegendGraphic glg = (GetLegendGraphic) req; format = glg.getFormat(); width = glg.getWidth(); height = glg.getHeight(); transparent = true; } else { return null; } return ImageUtils.prepareImage( format, width, height, transparent, bgcolor ); }
public static RenderContext createInstance( RenderingInfo info, OutputStream outputStream ) { BufferedImage image = ImageUtils.prepareImage( info.getFormat(), info.getWidth(), info.getHeight(), info.getTransparent(), info.getBgColor() ); return createInstance( info, image, outputStream); }