java圖片裁剪

來源:互聯網
上載者:User

總體思想:

    1.前台網頁用js得到裁剪圖片的id及x,y,寬度和高度。

    2.服務端根據id取出要裁剪的圖片 。

   3.根據這些參數來產生裁剪的映像。 
[代碼] java圖片裁剪 view sourceprint?

001 package com.wodexiangce;
002
003 import java.awt.Rectangle;
004
005 import java.awt.image.BufferedImage;
006
007 import java.io.File;
008
009 import java.io.FileInputStream;
010
011 import java.io.IOException;
012
013 import java.util.Iterator;
014
015 import javax.imageio.ImageIO;
016
017 import javax.imageio.ImageReadParam;
018
019 import javax.imageio.ImageReader;
020
021 import javax.imageio.stream.ImageInputStream;
022
023 /**
024  *
025  * 2012-10-25
026  *
027  */
028
029 public class OperateImage {
030
031     // ===源圖片路徑名稱如:c:\1.jpg
032
033     private String srcpath;
034
035     // ===剪下圖片存放路徑名稱。如:c:\2.jpg
036
037     private String subpath;
038
039     // ===剪下點x座標
040
041     private int x;
042
043     private int y;
044
045     // ===剪下點寬度
046
047     private int width;
048
049     private int height;
050
051     public OperateImage() {
052
053     }
054
055     public OperateImage(int x, int y, int width, int height) {
056
057         this.x = x;
058
059         this.y = y;
060
061         this.width = width;
062
063         this.height = height;
064
065     }
066
067     /**
068      *
069      * 對圖片裁剪,並把裁剪完的新圖片儲存 。
070      *
071      */
072
073     public void cut() throws IOException {
074
075         FileInputStream is = null;
076
077         ImageInputStream iis = null;
078
079         try {
080
081             // 讀取圖片檔案
082
083             is = new FileInputStream(srcpath);
084
085             /**
086              *
087              * 返回包含所有當前登入 ImageReader 的 Iterator,這些 ImageReader
088              *
089              * 聲稱能夠解碼指定格式。 參數:formatName - 包含非正式格式名稱 .
090              *
091              * (例如 "jpeg" 或 "tiff")等 。
092              

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.