Java picture cropping

Source: Internet
Author: User

General idea:

1. The front page uses JS to obtain the clipping picture ID and the x,y, the width and the height.

2. The server takes out the picture to be cropped based on the ID.

3. Based on these parameters, the cropped image is generated.
[code] Java picture crop 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 *
12V */
028
029 public class Operateimage {
030
031 = = Source Picture path name: c:\1.jpg
032
033 Private String Srcpath;
034
035 = = = Cut the picture to store the path name. such as: c:\2.jpg
036
037 Private String subpath;
13Y
039 = = = Cut point x coordinate
040
041 private int x;
042
043 private int y;
24v
045 = = = Cut Point width
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 }
16W
067 /**
068 *
069 * Crop the picture and save the cropped new picture.
070 *
071 */
072
073 public void Cut () throws IOException {
074
075 FileInputStream is = null;
076
077 Imageinputstream IIS = NULL;
078
079 try {
080
081 Reading picture files
082
083 is = new FileInputStream (Srcpath);
084
085 /**
086 *
18V * Returns the iterator containing all currently registered ImageReader, these ImageReader
088 *
089 * Claims to be able to decode the specified format. Parameters: FormatName-contains informal format names.
090 *
091 * (for example, "JPEG" or "TIFF").
092

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.