当前位置:编程学习 > JSP >>

java文字转成图片显示


package net.xdevelop.merge;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sun.image.codec.jpeg.*;
/**
 * @author Liao Xue Feng
 */
public class CreateImageServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        response.setContentType("image/jpeg");
        createImage(response.getOutputStream());
    }
    private void createImage(OutputStream out) {
    
     String text =" 测试";
    
        int width = 600;
        int height = text.length()/20*20;
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        // set background:
        g.setBackground(Color.GREEN);
        g.clearRect(0, 0, width, height);

        Font mFont = new Font("宋体",Font.PLAIN,20);//默认字体
        g.setColor(new Color(Integer.parseInt("000000",16)));
        g.setFont(mFont);
       
       
       
        int x=3;
        int y=3;
        int count = text.length();
        i补充:Jsp教程,Java基础

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,