在Windows下用JB9编程序,生成一张png图形,代码如下:void loadimage()
{
   BufferedImage img;
   int maxImageWidth=300;
   int maxImageHeight=200;
   img = new BufferedImage(maxImageWidth, maxImageHeight,
                           java.awt.image.BufferedImage.TYPE_INT_ARGB);
   img.getGraphics().setColor(Color.white);
   img.getGraphics().fillRect(0, 0, maxImageWidth, maxImageHeight);   String tt="汉字word";
   drawtext(img.getGraphics(),tt,x1,maxImageHeight-45,Color.red);   File file = new File("image.png");
   FileOutputStream fout = null;
   try {
     fout = new FileOutputStream(file);
     javax.imageio.ImageIO.write(img, "PNG", fout);
     fout.close();
   }
   catch (IOException ex2) {
   }
   fout = null;
   file = null;
   img = null;
}void drawtext(Graphics g,String text,int x,int y,Color color)
 {
     Font font;
     font = new Font("宋体", 0, 12);
     g.setFont(font);
     g.setColor(color);
     g.drawString(text,x,y);
 }生成图片文件image.png在windows系统中结果正常,但是把程序放到linux系统中运行生成的图片中的“汉字”就变成了方框了
请这方面的高手能给予解决 
    

解决方案 »

  1.   

    有可能是UNIX不支持你的字体。
      

  2.   

    这个需要修改一下linux下的一个配置文件,因为中文windows默认字符集就是GBK,而你的java工程为GBK的话就能正确处理中文;但是linux下可能就不这样,所以需要自己修改配置文件。另外还有种方法,就是不管什么操作系统都可以适用的,那就是将你的中文全部用i18n表示,也就是\uxxxx这样的格式。能完成这个工作的工具比较多,你随便搜索下都能搞定。
      

  3.   

    在linux下最好用unicode.用unicode应该就可以了
      

  4.   

    问题解决了:把linux上的JDK从1.4升级到1.5就可以了