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