- 浏览: 140078 次
- 性别:
- 来自: 厦门
最新评论
-
占星:
[b][flash=200,200][url][img][li ...
hibernate结合spring怎么处理对象的延迟加载? -
accphc:
...
处理properties文件中key包含空格和等号的情况 -
赵武艺:
有没有办法不让jfreechart热点刷新页面?
有热点的JfreeChart柱型图(原创)[转] -
yuchensuifeng:
谢谢分享!刚学这个,现在去试试!
在struts2中使用JFreeChart -
wrrwhn:
Caused by: There is no result t ...
在struts2中使用JFreeChart
最近对图片加上水印,有兴趣,找到一个牛人写的帖子,转载到这里,供大家分享!!!!!!
package net.csdn.xdj.model.d050403;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
/**
* <p>加入水印信息</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class Mark {
public Mark() {
}
public static ByteArrayOutputStream manipulateImage(String message,
byte[] imageData) {
ByteArrayOutputStream baos = null;
Frame frame = null;
Graphics graphics = null;
try {
frame = new Frame();
frame.addNotify();
MediaTracker mt = new MediaTracker(frame);
Image image = Toolkit.getDefaultToolkit().createImage(imageData);
mt.addImage(image, 0);
mt.waitForAll();
int w = image.getWidth(frame);
int h = image.getHeight(frame);
BufferedImage offscreen = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR);
graphics = offscreen.getGraphics();
graphics.drawImage(image, 0, 0, frame);
graphics.setColor(Color.RED);
graphics.setFont(new Font("宋体", Font.BOLD | Font.ITALIC, 20));
graphics.drawString(message, 9, 29);
graphics.setColor(Color.WHITE);
graphics.drawString(message, 10, 30);
baos = new ByteArrayOutputStream();
JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.
createJPEGEncoder(baos);
encoder.encode(offscreen);
}
catch (InterruptedException e) {
e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
}
catch (IOException e) {
e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
}
finally {
if (graphics != null) {
graphics.dispose();
}
if (frame != null) {
frame.removeNotify();
}
}
return baos;
}
}
package net.csdn.xdj.servlet.d050403;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.upload.FormFile;
/**
* <p>页面表单影射,Action FormBean</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class UploadAFB
extends ActionForm {
private String theAction;
private FormFile theFile;
private String newFile;
public void setTheAction(String theAction) {
this.theAction = theAction;
}
public String getTheAction() {
return this.theAction;
}
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
public void setNewFile(String newFile) {
this.newFile = newFile;
}
public FormFile getTheFile() {
return this.theFile;
}
public String getNewFile() {
return newFile;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (theAction != null) {
if (theFile == null) {
errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定上传文件"));
}
if (newFile == null & newFile.length() == 0) {
errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定保存文件路径"));
}
}
// verify
return errors;
}
}
package net.csdn.xdj.servlet.d050403;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.struts.upload.FormFile;
import java.io.*;
import net.csdn.xdj.model.d050403.Mark;
/**
* <p>上传处理,Action</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class UploadImage
extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) {
UploadAFB form = (UploadAFB) actionForm;
String theAction = form.getTheAction();
form.setTheAction("uploadImage");
if (theAction == null) {
theAction = "";
}
else if (theAction.equals("uploadImage")) {
FormFile file = form.getTheFile();
File newFile = new File(form.getNewFile());
if (file == null || newFile == null) {
return mapping.getInputForward();
}
try {
ByteArrayOutputStream baos = Mark.manipulateImage("许德建",
file.getFileData());
FileOutputStream fos = new FileOutputStream(newFile);
baos.writeTo(fos);
fos.close();
baos.close();
request.setAttribute("message", "上传成功");
return mapping.findForward("response");
}
catch (FileNotFoundException ex) {
// error handle
}
catch (IOException ex) {
// error handle
}
}
return mapping.getInputForward();
}
}
package net.csdn.xdj.model.d050403;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
/**
* <p>加入水印信息</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class Mark {
public Mark() {
}
public static ByteArrayOutputStream manipulateImage(String message,
byte[] imageData) {
ByteArrayOutputStream baos = null;
Frame frame = null;
Graphics graphics = null;
try {
frame = new Frame();
frame.addNotify();
MediaTracker mt = new MediaTracker(frame);
Image image = Toolkit.getDefaultToolkit().createImage(imageData);
mt.addImage(image, 0);
mt.waitForAll();
int w = image.getWidth(frame);
int h = image.getHeight(frame);
BufferedImage offscreen = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR);
graphics = offscreen.getGraphics();
graphics.drawImage(image, 0, 0, frame);
graphics.setColor(Color.RED);
graphics.setFont(new Font("宋体", Font.BOLD | Font.ITALIC, 20));
graphics.drawString(message, 9, 29);
graphics.setColor(Color.WHITE);
graphics.drawString(message, 10, 30);
baos = new ByteArrayOutputStream();
JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.
createJPEGEncoder(baos);
encoder.encode(offscreen);
}
catch (InterruptedException e) {
e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
}
catch (IOException e) {
e.printStackTrace(System.out); //To change body of catch statement use File | Settings | File Templates.
}
finally {
if (graphics != null) {
graphics.dispose();
}
if (frame != null) {
frame.removeNotify();
}
}
return baos;
}
}
package net.csdn.xdj.servlet.d050403;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.upload.FormFile;
/**
* <p>页面表单影射,Action FormBean</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class UploadAFB
extends ActionForm {
private String theAction;
private FormFile theFile;
private String newFile;
public void setTheAction(String theAction) {
this.theAction = theAction;
}
public String getTheAction() {
return this.theAction;
}
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
public void setNewFile(String newFile) {
this.newFile = newFile;
}
public FormFile getTheFile() {
return this.theFile;
}
public String getNewFile() {
return newFile;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (theAction != null) {
if (theFile == null) {
errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定上传文件"));
}
if (newFile == null & newFile.length() == 0) {
errors.add(errors.GLOBAL_ERROR, new ActionError("error", "没有指定保存文件路径"));
}
}
// verify
return errors;
}
}
package net.csdn.xdj.servlet.d050403;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.struts.upload.FormFile;
import java.io.*;
import net.csdn.xdj.model.d050403.Mark;
/**
* <p>上传处理,Action</p>
* <p>Title: community.csnd.net</p>
* <p>Description: java问题解答</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 自由人</p>
* @author 许德建(simonxuluo)
* @version 1.0
*/
public class UploadImage
extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) {
UploadAFB form = (UploadAFB) actionForm;
String theAction = form.getTheAction();
form.setTheAction("uploadImage");
if (theAction == null) {
theAction = "";
}
else if (theAction.equals("uploadImage")) {
FormFile file = form.getTheFile();
File newFile = new File(form.getNewFile());
if (file == null || newFile == null) {
return mapping.getInputForward();
}
try {
ByteArrayOutputStream baos = Mark.manipulateImage("许德建",
file.getFileData());
FileOutputStream fos = new FileOutputStream(newFile);
baos.writeTo(fos);
fos.close();
baos.close();
request.setAttribute("message", "上传成功");
return mapping.findForward("response");
}
catch (FileNotFoundException ex) {
// error handle
}
catch (IOException ex) {
// error handle
}
}
return mapping.getInputForward();
}
}
发表评论
-
Windows下手动安装PostgreSQL实践
2009-05-27 15:01 2583一、基本安装 1、下载postgresql-8.3. ... -
postgresql的安装
2009-05-27 11:05 5697postgresql是自由软件阵营中的一款很好的数据库软件,就 ... -
[转载]Struts2学习:配置篇之“0配置”和Annotation
2009-05-19 15:55 2914http://blog.csdn.net/CMTobby/ar ... -
struts2 标签 简介
2009-04-21 16:14 1593来源: http://blog.csdn.net/yul ... -
Eclipse下J2ME开发环境的配置
2008-11-04 20:09 9494配置Eclipse 就是要到sun的网站下载JDK, ... -
使用Struts2 annotation 的Type Conversion
2008-06-13 17:40 2171当需要在jsp页面传递一组对象到action的时候,普通的类型 ... -
在hibernate中实现oracle的自动增长
2008-04-30 16:42 4793根据hibernate的文档,有两种方式实现实体对象的主键自动 ... -
Linux 上安装 Subversion
2008-03-11 16:34 2348引用Subversion是一个自由/开源版本控制系统,具备强大 ... -
使用firebug获得省市区信息
2008-01-27 18:24 1213有些网页有省份和城市的连动信息,可以使用下面的javascri ... -
利用JavaMail收/发Gmail邮件(SSL)
2007-12-27 18:34 4039利用JavaMail收/发Gmail邮件(SSL) Gmai ... -
[jQuery]date-picker的使用
2007-12-06 08:49 2063使用这个插件要下载两个东西,一个是date-picker.js ... -
加图片水印,加文字水印
2007-11-16 14:05 1471这个是加 ... -
[转]玩转 Ubuntu:如何从源文件安装软件
2007-06-11 20:56 2525在班图中附带了丰富的 ... -
[转载]Linux下软件安装方法总结
2007-03-23 15:00 1740一、rpm包安装方式步骤: 1、找到相应的软件包,比如soft ... -
JAVA加密算法的实现用例
2007-01-20 21:28 3028对象 参数 algorithm 如:& ... -
手动安装ruby和rails
2007-01-06 15:26 2822进入软件开发行业也快一年了,很幸运一进入就加入了一个敏捷开发的 ...
相关推荐
图片上传加上水印, 采用.net技术 图片上传加上水印, 采用.net技术
C# 给图片加上文字或图片水印,通过使用GDI+ 给图片上加水印。实现了透明文字与透明图片水印。可设置水印位置。
springboot实现上传图片添加水印
很实用的一个图片上传得例子 图片上传:生成缩略图 加文字水印 图片水印 ...远程图片抓取(保存到本地)支持jpg、gif、bmp、png 图片抓取后自动以Auto+日期+原名称命名 输入远程图片地址(支持Html)
上传之前预览 ,上传到服务器后加文字水印 或者 图片水印,调用相应的方法即可
为解决部分用户使用其他用户资源重复上传相同信息的问题(如房产图、汽车图、商品图等),您可在用户上传图片资源前先进行全盲水印提取,若提取到水印图信息则证明该图片来自之前已有资源,并进行相应操作(如提醒...
七牛云上传图片实现添加水印java代码测试类注意事项要先获取七牛的ak,sk以及空间水印样式
一款很好的上传图片加水印的主键 后台可以设置上传图片水印的样式
jQuery图片自动添加水印插件是一款可以为图片添加自定义水印的jquery插件。
快速实现图片上传及预览+时间水印功能;可设置图片像素,大小,张数,时间水印; 一句代码即可实现,easy,easy,easy
用VB在图片上加上水印的程序,有源码在压缩包内。
上传图片的时候添加水印的功能,并且拥有图片自定义尺寸的功能。 2.5.3所有功能 <img src="images/main_0.gif" width="3" height="5" border="0" /> 1.支持.jpg|.gif|.png|.bmp|.tif等; 2.图片自定义缩放; 3...
Asp.net上传图片并添加水印,Asp.net 上传图片 水印 gdi+ 绘图
图片、文件上穿 uploadpicture 上传图片 uploadfile 上传文件 上传的图片可以盖文字或图片水印
图片加数字水印工具 图片批量加水印软件 数字水印 一键设置,轻松批量加水印
添加水印方法(水印图片,目标图片),添加在右下角(根据坐标显示) 针对网页图片添加水印,用java语言编写,很简单。 // 获取水印图片的路径 String planeImage = request.getSession().getServletContext()....
struts2 上传 java 图片水印 改变图片大小
java 图片添加水印 图片叠加文字类 图片生成方法,如果需要在已有的图片叠加文字
php实现上传图片并能控制是否加水印 php 上传图片 php加水印 上传图片 加水印 功能测试完全
图片上传(水印、缩略图、远程保存)源码!!!!!!!!