標籤: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 圖片裁剪