zk架構中java有關後台圖片上傳及尺寸控制

來源:互聯網
上載者:User

標籤: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有關後台圖片上傳及尺寸控制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.