This article introduces the iOS in the Acquisition System album pictures, in many applications can be used, you can get a single picture, you can get more than one picture, nonsense said, look below it.
I. Get a single picture
Ideas:
1. Use Uiimagepickercontroller to get pictures from the system's own app (photo camera)
2. Set up agent, comply with agency agreement
Note that this Uiimagepickercontroller class is more specific and requires compliance with two agent protocols
@interface Viewcontroller () <uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate>
3. How to implement the agent Didfinishpickingmediawithinfo
-(void) GETIMAGEFROMIPC {//1. Determine if the album can open if (![
Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) return; 2.
Create a picture selection controller Uiimagepickercontroller *IPC = [[Uiimagepickercontroller alloc] init]; /** typedef ns_enum (Nsinteger, Uiimagepickercontrollersourcetype) {uiimagepickercontrollersourcetypephotolibrary,/
/album Uiimagepickercontrollersourcetypecamera,//photo shoot for Uiimagepickercontrollersourcetypesavedphotosalbum//Photo albums * *//3.
Set Open photo album type (show all albums) Ipc.sourcetype = Uiimagepickercontrollersourcetypephotolibrary;
Ipc.sourcetype = Uiimagepickercontrollersourcetypesavedphotosalbum;
Camera//Ipc.sourcetype = Uiimagepickercontrollersourcetypecamera;
4. Set Agent ipc.delegate = self;
5.modal out of this controller [self PRESENTVIEWCONTROLLER:IPC animated:yes completion:nil]; #pragma mark-<uiimagepickercontrollerdelegate>--//Get Picture action-(void) Imagepickercontroller: ( Uiimagepickercontroller *) Picker DidfinIshpickingmediawithinfo: (nsdictionary<nsstring *,id> *) Info {//Destroy Controller [Picker Dismissviewcontrolleranimated:ye
S Completion:nil];
Set Picture Self.imageView.image = Info[uiimagepickercontrolleroriginalimage];
}
Two. Get more than one 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 single example, send a request to get pictures from asset
- Phimagerequestoptions Picture Request Options
- Note: This class is the method that the iOS8 begins to generalize before iOS9 begins to retire.
- Before the system fit IOS8, use the API in the library below
#import <AssetsLibrary/AssetsLibrary.h>
1. Get the original artwork of all albums
-(void) getoriginalimages
{
//Get all Custom albums
phfetchresult<phassetcollection *> *assetcollections = [ Phassetcollection Fetchassetcollectionswithtype:phassetcollectiontypealbum Subtype: Phassetcollectionsubtypealbumregular Options:nil];
Iterate through all the custom albums for
(Phassetcollection *assetcollection in assetcollections) {
[self Enumerateassetsinassetcollection:assetcollection Original:yes];
}
Get camera film
phassetcollection *cameraroll = [phassetcollection fetchassetcollectionswithtype: Phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumuserlibrary Options:nil].lastObject;
Traverse the camera film to get the big picture
[self enumerateassetsinassetcollection:cameraroll original:yes];
}
2. Get thumbnails in all albums
-(void) getthumbnailimages
{
//Get all Custom albums
phfetchresult<phassetcollection *> *assetcollections = [Phassetcollection Fetchassetcollectionswithtype:phassetcollectiontypealbum subtype: Phassetcollectionsubtypealbumregular Options:nil];
Iterate through all the custom albums for
(Phassetcollection *assetcollection in assetcollections) {
[self Enumerateassetsinassetcollection:assetcollection Original:no];
}
Get camera film
phassetcollection *cameraroll = [phassetcollection fetchassetcollectionswithtype: Phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumuserlibrary Options:nil].lastObject;
[Self enumerateassetsinassetcollection:cameraroll original:no];
}
3. Traverse Album
/** * Iterate through all the pictures in the album * @param assetcollection Albums * @param original whether to have the original * * (void) en Umerateassetsinassetcollection: (phassetcollection *) assetcollection Original: (BOOL) Original {NSLog (@ "album Name:%@",
Assetcollection.localizedtitle);
Phimagerequestoptions *options = [[Phimagerequestoptions alloc] init];
Get pictures synchronously, only return 1 pictures options.synchronous = YES; Get all the 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);
}]; }
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.