Reprint Address: http://blog.csdn.net/you_and_me12/article/details/7262988
This address is also good: http://smallwoniu.blog.51cto.com/3911954/1248695
Get an image resource from your SD card, or take a new picture.
Post Code First
Get Pictures:
Note: If you take a photo, you can specify a saved address for the picture, which is not indicated here.
[Java]View Plaincopy
- charsequence[] items = {"album", "Camera"};
- New Alertdialog.builder (this)
- . Settitle ("select Picture Source")
- . Setitems (items, new Onclicklistener () {
- public void OnClick (Dialoginterface dialog, int which) {
- if (which = = Select_picture) {
- Intent Intent = new Intent (intent.action_get_content);
- Intent.addcategory (intent.category_openable);
- Intent.settype ("image/*");
- Startactivityforresult (Intent.createchooser (Intent, "select Picture"), select_picture);
- }else{
- Intent Intent = new Intent (mediastore.action_image_capture);
- Startactivityforresult (Intent, Select_camer);
- }
- }
- })
- . Create (). Show ();
Process pictures, method One, directly process the return Picture:
Comments:
1, the Internet has a description, the direct processing of the returned image is compressed by the system, but their own in the process of testing is not different;
2, if the user constantly re-obtain the picture, must be the current BMP memory release, or will error! Bmp.recycle ().
[Java]View Plaincopy
- protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
- Super.onactivityresult (Requestcode, ResultCode, data);
- if (ResultCode = = RESULT_OK) {
- //Select Picture
- Uri uri = Data.getdata ();
- Contentresolver cr = this.getcontentresolver ();
- try {
- If (BMP! = null)//If not released, keep taking pictures, will not have enough memory
- Bmp.recycle ();
- BMP = Bitmapfactory.decodestream (Cr.openinputstream (URI));
- } catch (FileNotFoundException e) {
- //TODO auto-generated catch block
- E.printstacktrace ();
- }
- System.out.println ("The BMP toString:" + BMP);
- Imagesv.setbmp (BMP);
- }else{
- Toast.maketext (setimageactivity. This, "Please re-select Picture", Toast.length_short). Show ();
- }
- }
Process the picture, method two, get the address of the picture to be processed again:
[Java]View Plaincopy
- protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
- Super.onactivityresult (Requestcode, ResultCode, data);
- if (ResultCode = = RESULT_OK) {
- Uri uri = Data.getdata ();
- String [] Proj={mediastore.images.media.data};
- cursor cursor = managedquery (URI,
- Proj, //which columns to return
- NULL, //WHERE clause; which rows to return (all rows)
- NULL, //WHERE clause selection arguments (none)
- null); //order-by clause (ascending by name)
Android Select pictures from albums and photos