protected RenderedImage doFilter ( BufferedImage pImage , ServletRequest pRequest , ImageServletResponse pResponse ) { // Get angle double ang = getAngle ( pRequest ) ; // Get bounds Rectangle2D rect = getBounds ( pRequest , pImage , ang ) ; int width = ( int ) rect . getWidth ( ) ; int height = ( int ) rect . getHeight ( ) ; // Create result image BufferedImage res = ImageUtil . createTransparent ( width , height , BufferedImage . TYPE_INT_ARGB ) ; Graphics2D g = res . createGraphics ( ) ; // Get background color and clear String str = pRequest . getParameter ( PARAM_BGCOLOR ) ; if ( ! StringUtil . isEmpty ( str ) ) { Color bgcolor = StringUtil . toColor ( str ) ; g . setBackground ( bgcolor ) ; g . clearRect ( 0 , 0 , width , height ) ; } // Set mHints (why do I always get jagged edgdes?) RenderingHints hints = new RenderingHints ( RenderingHints . KEY_COLOR_RENDERING , RenderingHints . VALUE_COLOR_RENDER_QUALITY ) ; hints . add ( new RenderingHints ( RenderingHints . KEY_RENDERING , RenderingHints . VALUE_RENDER_QUALITY ) ) ; hints . add ( new RenderingHints ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_ON ) ) ; hints . add ( new RenderingHints ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BICUBIC ) ) ; g . setRenderingHints ( hints ) ; // Rotate around center AffineTransform at = AffineTransform . getRotateInstance ( ang , width / 2.0 , height / 2.0 ) ; // Move to center at . translate ( width / 2.0 - pImage . getWidth ( ) / 2.0 , height / 2.0 - pImage . getHeight ( ) / 2.0 ) ; // Draw it, centered g . drawImage ( pImage , at , null ) ; return res ; }
Reads the image from the requested URL rotates it and returns it in the Servlet stream . See above for details on parameters .