Android Select pictures from albums and photos

Source: Internet
Author: User

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
  1. charsequence[] items = {"album", "Camera"};
  2. New Alertdialog.builder (this)
  3. . Settitle ("select Picture Source")
  4. . Setitems (items, new Onclicklistener () {
  5. public void OnClick (Dialoginterface dialog, int which) {
  6. if (which = = Select_picture) {
  7. Intent Intent = new Intent (intent.action_get_content);
  8. Intent.addcategory (intent.category_openable);
  9. Intent.settype ("image/*");
  10. Startactivityforresult (Intent.createchooser (Intent, "select Picture"), select_picture);
  11. }else{
  12. Intent Intent = new Intent (mediastore.action_image_capture);
  13. Startactivityforresult (Intent, Select_camer);
  14. }
  15. }
  16. })
  17. . 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
  1. protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
  2. Super.onactivityresult (Requestcode, ResultCode, data);
  3. if (ResultCode = = RESULT_OK) {
  4. //Select Picture
  5. Uri uri = Data.getdata ();
  6. Contentresolver cr = this.getcontentresolver ();
  7. try {
  8. If (BMP! = null)//If not released, keep taking pictures, will not have enough memory
  9. Bmp.recycle ();
  10. BMP = Bitmapfactory.decodestream (Cr.openinputstream (URI));
  11. } catch (FileNotFoundException e) {
  12. //TODO auto-generated catch block
  13. E.printstacktrace ();
  14. }
  15. System.out.println ("The BMP toString:" + BMP);
  16. Imagesv.setbmp (BMP);
  17. }else{
  18. Toast.maketext (setimageactivity.   This, "Please re-select Picture", Toast.length_short). Show ();
  19. }
  20. }

Process the picture, method two, get the address of the picture to be processed again:

[Java]View Plaincopy
    1. protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
    2. Super.onactivityresult (Requestcode, ResultCode, data);
    3. if (ResultCode = = RESULT_OK) {
    4. Uri uri = Data.getdata ();
    5. String [] Proj={mediastore.images.media.data};
    6. cursor cursor = managedquery (URI,
    7. Proj, //which columns to return
    8. NULL, //WHERE clause; which rows to return (all rows)
    9. NULL, //WHERE clause selection arguments (none)
    10. null); //order-by clause (ascending by name)

Android Select pictures from albums and photos

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.