I am combined with JSPSmart.upload, this is the IMGBean code package com.pic;
Import java.awt. *; import java.awt.event. *; import java.io. *; import java.awt.image. *; import org.w3c.dom. *; import com.sun.image.codec. JPEG. *; import javax.imageio. *;
Public class imgbean_i {public void imgbean_i () {
}
public void ImgYin (String Imagename_biao, String ImgName) {try {File _file = new File (ImgName); Image src = ImageIO.read (_file); int wideth = src.getWidth (null); int height = src.getHeight (null BufferedImage Image = New BufferedImage (Wideth, Height, BufferedImage.Type_INT_RGB); Graphics G = Image.createGraphics (); g.drawImage (SRC, 0, 0, Wideth, Height, NULL);
// watermark file File _filebiao = new File (Imagename_biao); Image src_biao = ImageIO.read (_filebiao); int wideth_biao = src_biao.getWidth (null); int height_biao = src_biao.getHeight (null); g.drawImage (src_biao, wideth -110, height-110, wideth_biao, height_biao, null; // Watermark file in the original picture file location, the original picture file is wideth-0, Height-0 g.dispose (); fileoutputstream out = new fileoutputstream ( IMGNAME); JPEGIMAGEENCODER Encoder = JPEGCODEC.CREATEJPEGENCODER (OUT); Encoder.Encode (Image); out.close ();} catch (exception e) {system.out.println (e);}}}} The following is modified Smartupload code <% @ page language = "java" import = "com.jspsmart.upload. *" Import = "java.util. *, java.text. *"%> <% @ Page ContentType = "text / html; Charset = GBK "%>
<% int count = 0; string path = request.getRealPath (" "); mysmartupload.initialize (pagecontext); mysmartupload.upload ();
ConnectTodatabase (); for (int i = 0; i com.jspsmart.upload.file myfile = mysmartupload.getfiles (). getfile (i); if (! myfile.isming ()) {int size = myfile.getsize (); string filename = myfile.getFileName (); string filext = myfile.getfileext (); string UploadTime = new java.text.SIMPLEDATEFORMAT ("YYY-MM-DD HH: MM: SS"). Format (java.util.calendar.GetInstance (). gettime ()); if (); Size> = 1000000) {OUT.PRINTLN ("file more than 1000K!"); // Limit size} else {IF ((FileExt.equals ("JPG")) || (FileExt.Equals ("JPG")) | (FileExt.Equals ("GIF")) || ("GIF")))) {java.util.date date = new java.util.date (); SimpleDateFormat Formatter1 = New SimpleDateFormat ("YYYYMMDDHMMSS" ); String name1 = filename.substring (0, filename.indexof (".")); String name2 = filename.substring ("."), Filename.Length (); string newname = name1 formatter1 .format (date) Name2; //session.putValue ("Path1" ,newname); myfile.saveas ("/ photo / upfile /" newname); if (Integer.Parseint (Sy) == 1) {COM .P Ic.imgbean_i bbb = new com.pic.imgbean_i (); bbb.imgyin (Path "/ photo / images / shiyin.gif", Path /photo / upfile / " newname); // This is the source of the watermark file Address, you can modify the form of a drop-down menu value, so you can implement a text watermark or picture watermark} Stmt.executeUpdate ("Insert INTO IMG_PHOTO (Name, HTTP, Userid, ClassID, Title, Content, Imgsize, Format, Num , primflag, posttime) values () "); out.println (("
") .tostring ());} else {outputln (" file format is not right! ");}} count ;} else {Out.println ("