生成中文字的图少时乱码
生成中文字的图片时乱码
用以下代码(片段)生成中文字的图片,在windows下正常,在Liunx下乱码。
网上找各种解决办法,都不好使。
有人说Liunx下没有中文的字体设置,不清楚怎么做才能设置上呢?
如果不是输出到图片,只是显示在页面上,则没有乱码。
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0, width, height);
g.setColor(Color.blue);
// g.setFont(new Font("宋体",Font.PLAIN,18));
g.drawString("中文字", 15, 25);
g.dispose();
out.clear();
ImageIO.write(image, "JPEG", response.getOutputStream());
用以下代码(片段)生成中文字的图片,在windows下正常,在Liunx下乱码。
网上找各种解决办法,都不好使。
有人说Liunx下没有中文的字体设置,不清楚怎么做才能设置上呢?
如果不是输出到图片,只是显示在页面上,则没有乱码。
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0, width, height);
g.setColor(Color.blue);
// g.setFont(new Font("宋体",Font.PLAIN,18));
g.drawString("中文字", 15, 25);
g.dispose();
out.clear();
ImageIO.write(image, "JPEG", response.getOutputStream());
1 楼
hyhongyong
2007-03-14
请遇到过这个问题的人给指点一二,应该怎么做?
2 楼
Xiaohanne
2007-03-14
那段东东真眼熟,不是我写的那个吧。。。
Liunx下没有"宋体",页面上能出来时因为那个时候用得是客户端的字体
Liunx下没有"宋体",页面上能出来时因为那个时候用得是客户端的字体
3 楼
天之魔神
2007-03-15
为什么一定要用中文呢,java内部是unicode按说应该不会乱码吧