IOS get pictures from local albums based on picture URL

Source: Internet
Author: User

Recently done a chat item, need to send picture after reading local picture display to the list. At first, it was naïve to think that it was possible to load directly with sdwebimage and not be able to do it.

So on the Internet search, how to read from the Uiimagepickercontrollerreferenceurl from the photo album, the code is as follows:

#import "ViewController.h" #import <AssetsLibrary/AssetsLibrary.h> @interface Viewcontroller () < Uinavigationcontrollerdelegate, uiimagepickercontrollerdelegate>-(ibaction) SHOWIMAGEPICKERVC: (ID) sender;@ Property (weak, nonatomic) Iboutlet Uiimageview *imageview; @end @implementation viewcontroller-(void) Viewdidload {    [Super Viewdidload];   }

Pop-up picture selector

-(Ibaction) SHOWIMAGEPICKERVC: (ID) Sender {        Uiimagepickercontroller *imagepickervc = [Uiimagepickercontroller ALLOC] init];        Imagepickervc.sourcetype = uiimagepickercontrollersourcetypephotolibrary;    imagepickervc.allowsediting = YES;        Imagepickervc.delegate = self;        [Self PRESENTVIEWCONTROLLER:IMAGEPICKERVC animated:yes completion:nil];    }

Callback

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info    {NSLog (@ "%@", info);    Nsurl *imagepath = info[@ "Uiimagepickercontrollerreferenceurl"]; if ([[[[[[ImagePath Scheme] lowercasestring] isequaltostring:@ "Assets-library"]) {//Load from Asset Library Async Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{@autoreleasepool                    {@try {alassetslibrary *assetslibrary = [[Alassetslibrary alloc] init]; [Assetslibrary assetforurl:imagepath resultblock:^ (Alasset *asset)                                       {Alassetrepresentation *rep = [Asset defaultrepresentation];                                       Cgimageref Iref = [Rep fullscreenimage];                                        if (iref) {//UI Modified   Dispatch_sync (Dispatch_get_main_queue (), ^{_imageview.image = [[UIImage                                           Alloc] initwithcgimage:iref];                                                                                   });                                                                            }} failureblock:^ (Nserror *error) {                                                                        NSLog (@ "Get Picture from Gallery failed:%@", error);                }];                } @catch (NSException *e) {NSLog (@ "Get Picture exception from Gallery:%@", e);            }            }        }); } [Picker Dismissviewcontrolleranimated:yes completion:nil];}

IOS get pictures from local albums based on picture URL

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.