我觉得可以换个角度来考虑:
把这个图片作为一个panel的icon,然后在这个panel上用graphics或graphics2D中的drawString()方法来添加文字。或者加一个label。

解决方案 »

  1.   

    请大虾指教下面代码为何实现不了功能呢?
    应该如何修改?谢了先!!!String imageFile = "d:\1.jpg";
    InputStream imageIn = new FileInputStream(new File(imageFile));
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(imageIn);
    BufferedImage image = decoder.decodeAsBufferedImage();
    Graphics g=image.getGraphics();
    g.drawString(text,x,y);
    imageIn.close();
      

  2.   

    据我在Delphi中的实践经验所知,windows虽然可以方便地观看多种格式的图像文件,但除了bmp文件载入后就可在其图像上写字或画图像外,其余的非bitmap文件载入后都不能在其图像上写字或作任何改动,否则立即报错!要想在图像上写字或作任何改动,必须先将原有非bitmap图像格式转换为bitmap图像格式,然后再在屏幕(或在内存中的)图像上写字或作任何需要改动,改动完后,必要时,再将bitmap格式转换为原有图像格式.用java语言是否能这样作我不知道.Java我记得以前不支持bitmap图像的直接显示,但现在如何我也不知道了.
      

  3.   

    imageFile = getServletContext().getRealPath(imageFile);
                InputStream imageIn = new FileInputStream(new File(imageFile));
                JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(imageIn);
                BufferedImage image = decoder.decodeAsBufferedImage();
                Graphics g=image.getGraphics();            //设置颜色
                g.setColor(new Color(Integer.parseInt(fontColor,16)));            //设置字体
                Font mFont = new Font(fontName,Font.PLAIN,fontSize);//默认字体
                g.setFont(mFont);            //输出文字
                g.drawString(text,x,y);            //输出数据流
                JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
                encoder.encode(image);
                imageIn.close();
    这是从ibm dw上抄来的,对你应该有帮助。详见:
    http://www-900.ibm.com/developerWorks/cn/java/l-imgtxt/index.shtml
      

  4.   

    多谢各位!问题已解决。
    用Graphics的drawstring方法即可。
    结分。见者有份!