Java给图片加水印

/**
* 方法描述:<b>给图片增加水印.</b></br>
* 备 注: 在图片上写字符串
* 创 建 人: bo.gaobo</br>
* 创建日期: 2012-09-07</br>
* @param originalUrl 原始图片存储路径
* @param oldImg 原图片
* @param str 增加的字符串
* @param xLocation x坐标
* @param yLocation y坐标
* @param fontColor 颜色
* @param fontSize 字号
* @param typeFace 字体
* @param fileType 文件类型
*/
public static BufferedImage addStringToImg(String originalUrl, BufferedImage oldImg,String str,int xLocation,int yLocation, Color fontColor, int fontSize, String typeFace, String fileType) throws IOException{
FileOutputStream output = new FileOutputStream(originalUrl);
BufferedImage buffImg = oldImg;
Graphics2D g = buffImg.createGraphics();
g = buffImg.createGraphics();
g.drawImage(buffImg, null, 0, 0);
g.setColor(fontColor); //设置字体颜色
g.setFont(new Font(typeFace, Font.PLAIN, fontSize)); //设置字体和字号
g.drawString(str, xLocation, yLocation); //把字符串放在对应的坐标处
g.dispose();
ImageIO.write(buffImg, fileType, output); //设置文件类型
output.close();
return buffImg;
}

posted @ 2012-09-12 18:18  积累从点滴开始  阅读(1344)  评论(0编辑  收藏  举报