java 圖片裁剪

來源:互聯網
上載者:User

標籤:comm   col   source   tar   exce   stack   dep   stat   int   

圖片裁剪功能,我一直以為是前端那邊去做,後台不用做過多的考慮,現在我發現,前端去做裁剪好像不是太理想,我在這裡簡單地介紹一下我們大java的裁剪功能

前端只需要上傳,x (x軸),y(y軸) , h(高), w(寬),以上幾個座標點即可

以下是原圖

裁剪之後

 

 代碼如下,需要引入jar

public static void main(String[] args) {        // 在 C 盤的根目錄有一張 1.jpg 的圖片        File fromPic = new File("C:\\1.jpg");                try {//            Thumbnails.of(fromPic).sourceRegion(x, y, w, h).size(w, h).toFile(fromPic);            // toFile(fromPic) 會覆蓋原圖            Thumbnails.of(fromPic).sourceRegion(276, 23, 806, 670).size(806, 670).toFile(fromPic);        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }            }

 

 

<!-- 圖片處理,主要用於圖片縮放,縮圖產生等 -->        <dependency>            <groupId>net.coobird</groupId>            <artifactId>thumbnailator</artifactId>            <version>0.4.8</version>        </dependency>        <!-- 檔案上傳所需 start-->        <dependency>            <groupId>commons-fileupload</groupId>            <artifactId>commons-fileupload</artifactId>            <version>1.3.3</version>        </dependency>        <dependency>            <groupId>commons-io</groupId>            <artifactId>commons-io</artifactId>            <version>2.6</version>        </dependency>        <!-- 檔案上傳所需 end-->

 

以上就是圖片剪裁的全部代碼!!!

不喜勿噴!!!!!!!!!!!!!!!!!

 

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.