Private class Imagedeal implements EventListener {
private int type;
public imagedeal (int type) {
This.type = type;
}
public void OnEvent (Event arg0) throws Exception {
Switch (type) {
Case 1:
if (arg0 instanceof uploadevent) {
Uploadevent _eve = (uploadevent) arg0;
Media media = _eve.getmedia ();
if (null! = Media) {
if (media instanceof Org.zkoss.image.Image) {
Desktop des = executions.getcurrent (). Getdesktop ();
String name = Des.getsession (). Getwebapp ()
. Getrealpath ("");
Name + = File.separator + "IMGs" + file.separator;
Name + = File.separator + "IMGs" + file.separator
+ "255px" + file.separator;
string[] _tmp = Media.getname (). split ("\ \");
String fileName = Ppt.getid () + "."
+ _tmp[_tmp.length-1];
File File = new file (name + fileName);
if (File.exists ())
File.delete ();
Files.copy (file, Media.getstreamdata ());
Files.close (Media.getstreamdata ());
PPT.SETEXP2 (FileName);
String destpath=name + "255px" +file.separator+filename;
File DestFile = new file (destpath);
Image compression Processing
Imageutils image = new Imageutils (file, destfile);
Image.smallimg (255,178);
Showslt (); Show pictures
} else {
Edit Windows.showmess Yourself ("You are uploading files that are not of the type of the image, please try again");
}
}
}
Break
}
}
}
How to display pictures in my project
private void Showslt () {
Image tp = (image) This.getfellowifany ("TP");//ZK component
Tp.getchildren (). Clear ();
if (! Textutils.isempty (PPT.GETEXP2 ())) {
TP.SETSRC ("imgs/255px/" + PPT.GETEXP2 ());
}
}
A tool class for compressing picture processing
private void Showslt () {
Image tp = (image) This.getfellowifany ("TP");
Tp.getchildren (). Clear ();
if (! Textutils.isempty (PPT.GETEXP2 ())) {
TP.SETSRC ("imgs/255px/" + PPT.GETEXP2 ());
}
}
This article is from the "Origin" blog, please be sure to keep this source http://benyuan.blog.51cto.com/8521942/1637234
Java background image upload and dimension control in ZK framework