javaservlet实例:Java窍门技巧:例子讲解Servlet的图象处理来源: 发布时间:星期四, 2010年3月4日 浏览:137次 评论:0
我们在处理数据时
以下是引用片段: package test; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.awt.image.BufferedImage; import com.sun.image.codec.jpeg.*; import java.awt.image.*; import java.awt.*; public public void init(ServletConfig config) throws ServletException { super.init(config); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String sFileName = "e:/temp/name.jpg"; try{ FileOutputStream fos = FileOutputStream(sFileName); BufferedImage myImage = Graphics g = myImage.getGraphics g. g.fillRect(0,0,225,225); g. g.drawString("Finance Balance Summary", 40, 15); g.drawString("Primary", 90, 30); g. &g.fillRect(15,193,7,7); g. g.drawString("% Operating", 25, 200); g. g.fillRect(130,193,7,7); g. g.drawString("% Term", 140, 200); g. g.fillRect(15,213,7,7); g. g.drawString("% Mortgage", 25, 220); g. g.fillRect(130,213,7,7); g. g.drawString("% Lease", 140, 220); JPEGImageEncoder jpg = JPEGCodec.createJPEGEncoder(fos); jpg.encode(myImage); }catch (Exception e){ String exceptionThrown = e.toString String sourceOfException = " Method"; exceptionThrown + '\r' + '\n'); sourceOfException + '\r' + '\n'); } // CatchStatementEnd } } 0
相关文章
读者评论发表评论 |
