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