jsp的系统要加一个上传图片的功能...
如何才能上传的同时加一个水印?
如何才能上传的同时加一个水印?
解决方案 »
- 急!Filter过滤器对用户登陆资源访问的问题
- JBPM很好的一个详细介绍
- 求解 getHibernateTemplate问题
- jsp中调用servlet问题!(在线等!)
- strtus分页问题
- 数字计数器问题,急,帮帮忙!!
- jsp exception
- 请问SQL Server 2000中的SQL_Latin1_General_CP1_C1_AS排序规则语言是english(United states),在jsp中怎么设置其Charset?
- 请问各位师兄,poi的例子在什么地方!
- UTF8与GBK编码问题
- Java程序连接mysql时出错是为什么?
- jsp第一次连接mysql的菜鸟问题,请大家帮帮忙。
*
* <p>Title: 给图片添加水印</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: 福瑞网络有限公司</p>
* <p>[email protected]</p>
* @author 杨轶
* @version 1.0
*/
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;
import java.text.AttributedCharacterIterator;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
import java.util.regex.Pattern;public class PicShuiYin {
/**
* 给图片添加水印
* @param filePath 需要添加水印的图片的路径
* @param Content 水印的文字
* @param ContentColor 水印文字的颜色
* @param qualNum 图片质量
* @return
*/
public boolean createMark(String filePath, String sy_pic_path,
String Content, Color ContentColor,
String fontStyle, int fontSize, float qualNum) { //图片
ImageIcon imgIcon = new ImageIcon(filePath);
Image theImg = imgIcon.getImage();
int width = theImg.getWidth(null);
int height = theImg.getHeight(null);
BufferedImage bimage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);// 水印图片
ImageIcon imgIcon1 = new ImageIcon(sy_pic_path);
Image theImg1 = imgIcon1.getImage();
Font f = new Font(fontStyle, Font.BOLD, fontSize);
AttributedString ats = new AttributedString(Content);
ats.addAttribute(TextAttribute.FONT, f, 0, Content.length());
AttributedCharacterIterator iter = ats.getIterator(); Graphics2D g = bimage.createGraphics();
g.setColor(ContentColor);
g.setBackground(Color.white);
//g.setFont(new Font(Content, fontStyle, fontSize));
g.drawImage(theImg, 0, 0, null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1f)); //添加图片水印
g.drawImage(theImg1, width - 530, height -80, null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
//g.drawString(iter, width - 120, height - 10); //添加水印的文字和设置水印文字出现的内容 和位置
g.dispose();
try {
FileOutputStream out = new FileOutputStream(filePath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(bimage);
out.close();
} catch (Exception e) {
return false;
}
return true;
} public static void main(String[] args) {
PicShuiYin wm = new PicShuiYin();
if (wm.createMark("f://11.jpg", "f://logo.png", "要加的文字", Color.white, "华文彩云",
20,100f)) {
System.out.println("添加水印成功!");
} else {
System.out.println("添加水印失败!");
}
}
这句什么意思啊???