Java cropping pictures

Source: Internet
Author: User

Java cropped picture saved to the specified location

/*** Picture Clipping Universal Interface * *@paramsrc source picture address, image format PNG *@paramdest Destination Image address *@paramx Image starting point x coordinate *@paramY Picture starting point y coordinate *@paramW Picture Width *@paramh Picture Height *@throwsIOException Exception Handling*/     Public voidCutimage (string src, String dest,intXintYintWinth) {Try{            //get the PNG image of the ImageReader iteratorIterator Iterator = imageio.getimagereadersbyformatname ("PNG"); //get ImageReader according to iteratorImageReader reader =(ImageReader) iterator.next (); //get source picture input streamInputStream in =NewFileInputStream (SRC); //get Imageinputstream stream based on source picture input streamImageinputstream IIS =Imageio.createimageinputstream (in); //load the Imageinputstream stream into the ImageReaderReader.setinput (IIS,true); //Picture Reading ParametersImagereadparam param =Reader.getdefaultreadparam (); Rectangle rect=NewRectangle (x, Y, W, h); //Parameter objects set a rectangle of a certain sizeparam.setsourceregion (rect); //ImageReader get bufferedimage based on parameter objectBufferedImage bi = reader.read (0, param); //writes a picture stream filtered by a parameter object to the destination fileImageio.write (BI, "PNG",NewFile (dest)); }Catch(IOException e) {System.err.println ("Crop picture failed"); }    }

Source

Java cropping pictures

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.