Java background image upload and dimension control in ZK framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.