import java.io.*;
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;
public class testPhoto{
public static void main(String[]args) throws ImageFormatException, IOException {
InputStream is = new FileInputStream("C://Documents and Settings//Administrator.11C4A0557D91440//桌面//2.jpg");
//通过JPEG图象流创建JPEG数据流解码器
JPEGImageDecoder jpegDecoder = JPEGCodec.createJPEGDecoder(is);
//解码当前JPEG数据流,返回BufferedImage对象
BufferedImage buffImg = jpegDecoder.decodeAsBufferedImage();
//得到画笔对象
Graphics g = buffImg.getGraphics();
String word=" 2005-3-1 星期日 晴 北京";
int length=word.length();
System.out.print(length+"-"+buffImg.getWidth());
//设置颜色。
g.setColor(Color.RED);
//最后一个参数用来设置字体的大小
Font f = new Font("宋体",Font.BOLD,16);
g.setFont(f);
//10,20 表示这段文字在图片上的位置(x,y) .第一个是你设置的内容。
g.drawString(word,buffImg.getWidth()-length*11,buffImg.getHeight()-20);
g.dispose();
OutputStream os = new FileOutputStream("C://Documents and Settings//Administrator.11C4A0557D91440//桌面//4.jpg");
//创键编码器,用于编码内存中的图象数据。
JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
en.encode(buffImg);
is.close();
os.close();
System.out.println ("合成结束。。。。。。。。");
}
}