200分,请高手帮忙!linux上的图片处理问题。
我是用servlet画了个图片,汉字显示成方框,怎么办?
package untitled2;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import java.awt.image.BufferedImage;
import java.awt.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "image/jpeg; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
try
{
int newwidth=100;
int newheight=100;
BufferedImage image;
//绘制缩略图
BufferedImage buffImg = new BufferedImage(newwidth,newheight,BufferedImage.TYPE_INT_RGB);
Graphics g = buffImg.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0,newwidth,newheight);
g.setColor(Color.black);
g.drawString("张维全",50,10);
g.drawString(new String("张维全".getBytes(),"GBK"),50,20);
g.drawString(new String("张维全".getBytes("ISO8859_1"),"GBK"),50,30);
g.drawString(new String("张维全".getBytes("ISO8859_1"),"GB2312"),50,40);
g.drawString(new String("张维全".getBytes(),"GB2312"),50,50);
g.drawString(new String("张维全".getBytes(),"ISO8859_1"),50,60);
g.dispose();
//输出缩略图
java.io.OutputStream tempout=null;
tempout=response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(tempout);
encoder.encode(buffImg);
//
if(tempout!=null)
tempout.close();
}
catch(Exception e){
System.out.println("picTest:"+e.getMessage());
}
}
//Clean up resources
public void destroy() {
}
}