Ios--app Custom albums-get pictures from your custom albums

Source: Internet
Author: User

I. Get a single picture idea:
    • 1. Use Uiimagepickercontroller to get pictures from your system's own app (Photos \ Camera)
    • 2. Set up the agent, abide by the agent agreement
      • 注意This UIImagePickerController class is special and requires compliance with two agent protocols
        @interface ViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
    • 3. Ways to implement ProxiesdidFinishPickingMediaWithInfo
- (void) getimagefromipc{1. Determine if the album can be openedif (![Uiimagepickercontroller issourcetypeavailable:Uiimagepickercontrollersourcetypephotolibrary])Return2. Create a picture selection controllerUiimagepickercontroller *IPC = [[Uiimagepickercontroller alloc] init];/** typedef ns_enum (Nsinteger, Uiimagepickercontrollersourcetype) {uiimagepickercontrollersourcetypephotolibrary,/ /album Uiimagepickercontrollersourcetypecamera,//Camera capture Uiimagepickercontrollersourcetypesavedphotosalbum//albums} */3. Set Open photo album type (show all albums) Ipc.sourcetype =Uiimagepickercontrollersourcetypephotolibrary;Ipc.sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum;CameraIpc.sourcetype = Uiimagepickercontrollersourcetypecamera;4. Set Proxy ipc.delegate =Self5.modal out of this controller [self presentviewcontroller:ipc animated:YES completion:< Span class= "hljs-literal" >nil];}  #pragma mark--<uiimagepickercontrollerdelegate>--< Span class= "hljs-comment" >//action after getting the picture-(void) Imagepickercontroller: (uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( Nsdictionary<nsstring *,id> *) info{//destruction Controller [Picker Dismissviewcontrolleranimated:yes Completion:nil]; //set picture self.imageview.image = info[ uiimagepickercontrolleroriginalimage];}        
Two. Get multiple picture ideas:
    • Import Header File#import <Photos/Photos.h>
    • Phasset: A resource, such as a picture \ Video
    • Phassetcollection: A photo album
    • Phimagemanager Picture Manager, is a singleton, sending a request to get a picture from asset
    • Phimagerequestoptions Picture Request Options
    • Note: This class is the way iOS8 started to generalize, iOS9 before it started to be discarded.
      Before the system fits IOS8, use the API in the following library
      #import <AssetsLibrary/AssetsLibrary.h>
1. Get the original picture of all albums
- (void) getoriginalimages{Get all Custom albums phfetchresult<phassetcollection *> *assetcollections = [phassetcollectionFetchassetcollectionswithtype:phassetcollectiontypealbumsubtype:phassetcollectionsubtypealbumregular Options:nil]; //Traverse all the custom albums for (Phassetcollection *assetcollection in assetcollections) {[ Self Enumerateassetsinassetcollection:assetcollection Original:yes]; } //Get camera roll phassetcollection *cameraroll = [phassetcollection fetchassetcollectionswithtype: Phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumuserlibrary Options:nil]. Lastobject; //traverse the camera roll to get a larger image [self enumerateassetsinassetcollection:cameraroll original:yes];}    
2. Get thumbnails from all albums
- (void) getthumbnailimages{Get all Custom albums phfetchresult<phassetcollection *> *assetcollections = [phassetcollectionfetchassetcollectionswithtype:phassetcollectiontypealbum  Subtype:phassetcollectionsubtypealbumregular options:nil]; //traverse all custom albums for (phassetcollection *assetcollection in assetcollections) {[Self enumerateassetsinassetcollection: Assetcollection original:no]; } //get camera roll phassetcollection *cameraroll = [phassetcollection  Fetchassetcollectionswithtype:phassetcollectiontypesmartalbum subtype: Phassetcollectionsubtypesmartalbumuserlibrary options:nil].lastobject; [Self enumerateassetsinassetcollection:cameraroll original: NO];}              
3. Traverse the album
/** * Traverse all pictures in the album *@param assetcollection Photo Album *@param original If you want the original */-(voidEnumerateassetsinassetcollection: (phassetcollection *) assetcollectionOriginal: (BOOL) original{NSLog (@"Photo Album name:%@", assetcollection.localizedtitle); Phimagerequestoptions *options = [[Phimagerequestoptions alloc] init];Synchronize to get the picture, will only return 1 pictures options.synchronous = YES;//Get all Phasset objects in a photo album Phfetchresult<phasset *> *assets = [Phasset fetchassetsinassetcollection: Assetcollection Options:nil]; For (Phasset *asset in assets) { //Do you want the original cgsize size = original? Cgsizemake (Asset.pixelwidth, asset.pixelheight): Cgsizezero; //Get pictures from asset [[Phimagemanager Defaultmanager] requestimageforasset:asset targetsize:size  Contentmode:phimagecontentmodedefault options:options resulthandler:^ (UIImage * _nullable result, Nsdictionary * _nullable info) {NSLog (@"%@", result);}]; }}

 

Ios--app Custom Albums-get pictures from your custom albums

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.