码迷,mamicode.com
首页 > 编程语言 > 详细

zk框架中java有关后台图片上传及尺寸控制

时间:2015-04-23 00:42:26      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:java zk 图片

      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);

                            //图片压缩处理
                            ImageUtils image = new ImageUtils(file, destFile);
                            image.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());
        }
    }

本文出自 “本源” 博客,请务必保留此出处http://benyuan.blog.51cto.com/8521942/1637234

zk框架中java有关后台图片上传及尺寸控制

标签:java zk 图片

原文地址:http://benyuan.blog.51cto.com/8521942/1637234

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!