<% @ page language = "java" contenttype = "charset = GB2312"%> <% response.sethead ("cache-control", "no-store"); // http 1.1 response.setheader ("pragma", " No-cache "); // http 1.0 response.SetdateHeader (" expires ", 0); // prevents caching at the proxy server%> <% @ Page Import =" java.io.outputstream "%> <% @ Page Import = "java.awt.image. *"%> <% @ page import = "java.awt. *, java.awt.font. *, javax.imageio. *, java. IO. * "%>
<% @ Page Import = "com.sun.image.codec.jpeg. *"%> <% @ page import = "Acec. *, java.util. *"%>
Int width = 600;
INT height = 400;
INT innerHeight = height-100; int innerwidth = width-20;
INT maximum = 0;
For (int i = 0; i
Response.setContentType ("Image / JPEG"); bufferedimage bi = new bufferedimage (width, height, bufferedimage.type_int_rgb);
Graphics2d bicontext = bi.creategraphics ();
// Plug into background pattern try {image image = imageio.read (new file ("bg.jpg")); BICONText.drawImage (image, 0, 0, width, height, null);} catch (Exception EX) {system .out.println (EX.TOString ());
// Start drawing
Int barwidth = innerwidth / (DataValues.length * 4);
//System.out.println ("barwidth=" barwidth );for(int i = 0, II = 0; i Bicontext.setColor (Barcolor); Rectangle BarRect = New Rectangle (Barwidth, Barheight); // take the word width Font f = biContext.getFont (); FontRenderContext context = biContext.getFontRenderContext (); Rectangle2D bounds_top = f.getStringBounds ( "Popular Value:" currentValue, context); Rectangle2D bounds = f.getStringBounds (datanames [i], context); Bicontext.SetColor (color.black); // Cylindrical positioning int locationy = Height-BarHeight-20; int locationX = innerwidth / datavalues.length * (i 1) -barwidth / 2; if (DataValues.Length% 2! = 0) LocationX = Innerwidth / ( DataValues.Length 1) * (i 1) -barwidth / 2; BarRect.SetLocation (LocationX, Locationy); Bicontext.drawString (Datanames [i], (int) (((LocationX Barwidth / 2) -Bounds.Getwidth () / 2), Height-5); Bicontext.drawstring ("Personality:" CurrentValue, (INT) ((LocationX Barwidth / 2) -bounds_top.getwidth () / 2), LocationY-10; Bicontext.SetPaint (New GradientPaint (LocationX, Locationy, Barcolor1, LocationX Barwidth, Locationy, Barcolor); Bicontext.Fill (BarRect);} ///save Picture/ OutputStream bos = new FileOutputStream (application.getRealPath ( "tp.jpeg")); JPEGImageEncoder encoder1 = JPEGCodec.createJPEGEncoder (bos); encoder1.encode (bi); bos.close ();%>