Android pick album picture and crop

Source: Internet
Author: User

Preface the Android application often encounter the need to upload photo album pictures, here to record how to make photo album image selection and cropping.
Photo Album Select picture 1. Activate the album or File Manager to get the photos, the code is as follows:
private static final int take_picture_from_album = 1;private void Takepicturefromalbum () {Intent Intent = new Intent (inten t.action_get_content); Intent.settype ("image/*"); Startactivityforresult (Intent, take_picture_from_album);}
2. With the Startacitivityforresult () method, we can get the URI of the picture in Onacitivityresult () and then pass the URI of the picture to the picture clipping function with the following code:
@Overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (ResultCode = = Activity.result _OK) {switch (requestcode) {case Take_picture_from_album:if (data! = null) {Croppicturefromalbum (Data.getdata ());} Break;case picture_crop_code:if (data = null) {//This is the bitmapbitmap of the cropped picture bitmap = Data.getparcelableextra ("Data");} Break;default:break;}}} private static final int take_picture_from_album = 1;private void Takepicturefromalbum () {Intent Intent = new Intent (inten t.action_get_content); Intent.settype ("image/*"); Startactivityforresult (Intent, take_picture_from_album);} private static final int picture_crop_code = 2;private void Croppicturefromalbum (Uri pictureuri) {Intent Intent = new Inte NT ("Com.android.camera.action.CROP"); Intent.setdataandtype (Pictureuri, "image/*"); Intent.putextra ("CROP", "true" )////Crop frame ratio intent.putextra ("Aspectx", 1), Intent.putextra ("Aspecty", 2);//The size of the input picture after cropping Intent.putextra ("Outputx", 300 ); Intent.putextra ("Outputy", 300);//Remove Face recognition Intent.puTExtra ("Nofacedetection", true); Intent.putextra ("Return-data", true); Startactivityforresult (Intent, PICTURE_CROP_ CODE);}
3. In Onactivityresult, the Data.getparcelableextra ("data") can be used to get the bitmap after the image is cropped, and then the bitmap can be assigned to the picture control.



Android pick album picture and crop

Related Article

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.