如何把客户端上传的图片 先 加上水印再保存到服务端??????
如题:要求是先把上传的图片加好水印,再保存到服务器上
当然,有个变通的方法:先保存上传的图片在服务器上,再对图片做水印效果,但不想多出这么个步骤来处理
问题点数:50、回复次数:16Top
1 楼hanyun229(云)回复于 2005-04-02 15:51:02 得分 0
客户上传的图片,我怎样得到图片的二进制信息,再对二进制信息做图片方面的处理Top
2 楼hanyun229(云)回复于 2005-04-02 15:53:44 得分 0
最好有简单代码来示范,当然有处理的思路也非常的感谢Top
3 楼hanyun229(云)回复于 2005-04-02 17:01:11 得分 0
怎么没有人回答呢???Top
4 楼jdskyy(蒋传德)回复于 2005-04-03 03:28:39 得分 5
可能是分太少了吧!Top
5 楼jdskyy(蒋传德)回复于 2005-04-03 03:29:34 得分 0
200分买个原码^-^Top
6 楼hanyun229(云)回复于 2005-04-03 10:46:07 得分 0
200分买个原码,没有问题,只要有再多点也可以Top
7 楼java_jing(梦鸟)回复于 2005-04-03 10:55:41 得分 0
up,Top
8 楼ddroyce()回复于 2005-04-03 11:14:08 得分 5
处理的是*.dwg吗?是的话用vb处理方便些.Top
9 楼hanyun229(云)回复于 2005-04-03 11:27:26 得分 0
主要处理的是*.gif和*.jpg,也许还有*.bmp,好像格式倒是没有多大区别的,功能我可以去实现。
问题是把上传图片的信息提取成二进制信息后,不知道怎么对二进制信息处理水印问题
不过是一定要用JAVA的Top
10 楼jianghuxing(回头看看原来我一无所有)回复于 2005-04-03 11:41:07 得分 0
UP,Top
11 楼simonxuluo(爱江山更爱美人)回复于 2005-04-03 12:22:42 得分 10
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;
}
}
Top
12 楼simonxuluo(爱江山更爱美人)回复于 2005-04-03 12:23:04 得分 10
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;
}
}
Top
13 楼simonxuluo(爱江山更爱美人)回复于 2005-04-03 12:23:16 得分 20
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();
}
}
Top
14 楼yzh315(yzh)回复于 2005-04-03 12:43:06 得分 0
顶
Top
15 楼hanyun229(云)回复于 2005-04-08 10:24:20 得分 0
simonxuluo(爱江山更爱美人)
谢谢了
这几天在忙着,今天才上来,等会去看
再问一下
graphics.drawString(message, 9, 29);
我如何才能控制message字符串的宽度随着图片的大小而自动调整
就是随着图片的width与height设置字体的大小,而不是定20
graphics.setFont(new Font("宋体", Font.BOLD | Font.ITALIC, 20));
发贴这么长时间也没有结,不好意思,下午我就结贴,Top
16 楼AgathaZ(游弋的小鱼)回复于 2005-04-08 10:49:53 得分 0
mark!Top




