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.p_w_picpath.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);
//图片压缩处理
ImageUtils p_w_picpath = new ImageUtils(file, destFile);
p_w_picpath.smallImg(255,178);
//showSlt();显示图片
} else {
//自己编辑windows.showMess("您上传的不是图片类型的文件,请重试");
}
}
}
break;
}
}
}
//本人项目中显示图片的方法
private void showSlt() {
Image tp = (Image) this.getFellowIfAny("tp");//zk组件
tp.getChildren().clear();
if (!TextUtils.isEmpty(ppt.getExp2())) {
tp.setSrc("imgs/255px/" + ppt.getExp2());
}
}
压缩处理图片的工具类
private void showSlt() {
Image tp = (Image) this.getFellowIfAny("tp");
tp.getChildren().clear();
if (!TextUtils.isEmpty(ppt.getExp2())) {
tp.setSrc("imgs/255px/" + ppt.getExp2());
}
}