The strongest android in history to open a photo or to select a picture from a local album after the first crop in the save and display the source of the explanation attached

Source: Internet
Author: User
Tags crop image

The layout of the whole program is simple

A linear layout in a vertical direction with two buttons (button) and a control to display the picture (ImageView)
This part of the code is not given here.

1. Is the album that opens the system

Intent (Intent.  Action_picknull); Albumintent.setdataandtype (MediaStore.Images.Media.  External_content_uri"image/*"album_ok);
Here is a local album opened by the implicit intent of starting a system
2. It's the camera that opens the system.
Intent (Mediastore.  Action_image_capture); ///The following sentence specifies the path of the photo storage after the camera is called  (pre. Exists ()) {    pre. Delete ();}  {    pre(IOException e) {    e.printstacktrace ();} Cameraintent.putextra (Mediastore.  Extra_output, Uri.fromfile (precamera_ok);
Open the camera by opening an implicit intent
3. Cropping the clipping here is also through an implicit intent to invoke the function of the system
/** * Crop image method implementation  *   Image source */Clipphoto (Uri uri) {Intent (       "Com.android.camera.action.CROP");    "image/*");    Intent.putextra ("crop""true");    //Aspectx aspecty is the ratio of width to height, where the square is set (aspect ratio is 1:1)Intent.putextra ("Aspectx", 1);    Intent.putextra ("Aspecty", 1);    //Outputx outputy is a cropped image with a wide height of Intent.putextra ("OUTPUTX");    Intent.putextra ("outputy");    Intent.putextra ("Return-data"true);    cut_ok);}
4. Display and save pictures
/** * Save the picture data after cropping to set the picture to ImageView  *  picdata */Setpictoview (Intent picdata) {clog.d     (TAG  "Display the picture on the control");    Bundle extras = Picdata.getextras ();     null) {        = extras.getparcelable ("Data");         TODO Set the picture before you should delete the previous picture, save the latest picture Readbitmap2file (bitmap);        Headphoto. Setimagebitmap (bitmap);    }}
The following is the source code for the entire program (which also includes a team image for two samples of the tool class)
There is a problem to be verified.
When I saved the picture, it was my practice to determine if the SDcard card was available,
Unavailable cases are saved directly to the phone memory, in this place, someone and I mentioned that it seems that due to certain problems, it cannot be saved to this place.
If available, save directly on the SDcard card.
Click to download source code

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The strongest android in history to open a photo or to select a picture from a local album after the first crop in the save and display the source of the explanation attached

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.