
Code
1
import java.awt.*;
2
import java.awt.event.*;
3
import java.io.*;
4
import java.awt.image.*;
5
import org.w3c.dom.*;
6
import com.sun.image.codec.jpeg.*;
7
import javax.imageio.*;
8
9
public class ImgBean
{
10
public void ImgBean()
{}
11
public void ImgYin(String s,String ImgName)
{
12
try
{
13
File _file = new File(ImgName);
14
Image src = ImageIO.read(_file);
15
int wideth=src.getWidth(null);
16
int height=src.getHeight(null);
17
BufferedImage image=new BufferedImage(wideth,height,BufferedImage.TYPE_INT_RGB);
18
Graphics g=image.createGraphics();
19
g.drawImage(src,0,0,wideth,height,null);
20
String s="我要加的水印";
21
g.setColor(Color.RED);
22
g.setFont(new Font("宋体",Font.PLAIN,20));
23
Font aa=new Font("宋体",Font.PLAIN,20);
24
25
g.drawString(s,wideth-150,height-10);
26
g.dispose();
27
FileOutputStream out=new FileOutputStream(ImgName);
28
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
29
encoder.encode(image);
30
out.close();
31
}
32
catch(Exception e)
{
33
System.out.println(e);
34
}
35
}
36
}
posted @
2009-02-08 20:23
瞭望者
阅读(
91)
评论()
收藏
举报