IOS image acquisition (photo taking, Image Library, album), ios image library
There are three methods for iOS to get images
1. directly call the camera to take a photo
2. Select from album
3. Select from Image Library
UIImagePickerController is an interface provided by the system to obtain images and videos;
Use the UIImagePickerController class to obtain images and videos;
The procedure is as follows:
There are three data source types:
Enum {UIImagePickerControllerSourceTypePhotoLibrary, // from Image Library UIImagePickerControllerSourceTypeCamera, // from camera UIImagePickerControllerSourceTypeSavedPhotosAlbum/from album };
When using these sources, it is best to check whether the following devices are supported;
If ([UIImagePickerController isSourceTypeAvailable: available]) {NSLog (@ "camera supported");} if ([UIImagePickerController isSourceTypeAvailable: available]) {NSLog (@ "");} if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {NSLog (@ "Photo Library Supported ");}
Call the camera to obtain resources
- (void)viewDidLoad { [super viewDidLoad]; picker = [[UIImagePickerController alloc]init]; picker.view.backgroundColor = [UIColor orangeColor]; UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeCamera; picker.sourceType = sourcheType; picker.delegate = self; picker.allowsEditing = YES;}
The above is just an example of UIImagePickerController and Its Attributes. You need to call it in a pop-up window when you need to obtain the image.
[self presentViewController:picker animated:YES completion:nil];
We also need a proxy to retrieve the selected image.
UIImagePickerControllerDelegate
There are three methods in the proxy, one of which is 3.0 obsolete, and there are only two
-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info;
Called after user selection is complete;
-(Void) imagePickerControllerDidCancel :( UIImagePickerController *) picker;
Called when the user cancels the selection;
-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info;
The selected information is in info.
Info is a dictionary
Keys in the dictionary
NSString * const UIImagePickerControllerMediaType; specifies the selected media type (expanded at the end of the article) NSString * const category; original image NSString * const category; Modified Image NSString * const UIImagePickerControllerCropRect; crop NSString * const UIImagePickerControllerMediaURL; media URLNSString * const region; original URLNSString * const UIImagePickerControllerMediaMetadata; this value is valid only when the data source is a camera.
UIImagePickerController for more parameters refer to http://blog.sina.com.cn/s/blog_68edaff101019ppe.html
In the proxy function reference http://bbs.9ria.com/forum.php? Mod = viewthread & tid = 244453.
UIImagePickerControllerMediaType contains
KUTTypeImage inclusion
Const uses kUTTypeImage; the Abstract Image Type const CFStringRef kUTTypeJPEG; const CFStringRef kuttype2000; const CFStringRef kUTTypeTIFF; const CFStringRef kUTTypePICT; const CFStringRef comment; const has been added; const CFStringRef kUTTypeAppleICNS const CFStringRef kUTTypeBMP; const CFStringRef kUTTypeICO;
KUTTypeMovie inclusion
Const CFStringRef kUTTypeAudiovisualContent; abstract sound video const CFStringRef kUTTypeMovie; abstract media format (sound and video) const CFStringRef kUTTypeVideo; only the video has no sound const CFStringRef kUTTypeAudio; only video const CFStringRef kUTTypeQuickTimeMovie; const CFStringRef kUTTypeMPEG; const CFStringRef kUTTypeMPEG4; const CFStringRef kUTTypeMP3; const CFStringRef cursor;
For IOS, how does one obtain image information in a local album?
Copy the photo and Use ACDSee to view the EXIF information.
How can I obtain the name and the following details of the photo album on the IOS7 photo app through code?
Try the following code. I tested it on my mobile phone.
The principle is to enumerate each assets group and obtain the group property. The group property is an integer that corresponds to some enumeration values in the header file. This can be used to determine where the photo comes from (camera film, photo stream, and album ), in addition, you can use persistent id to determine whether the photo is created from a device or from my computer.
ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];
[Library enumerateGroupsWithTypes: ALAssetsGroupAll
UsingBlock: ^ (ALAssetsGroup * group, BOOL * stop)
{
NSLog (@ "% @", group );
[Group setAssetsFilter: [ALAssetsFilter allAssets];
NSLog (@ "Name: % @", [group valueForProperty: ALAssetsGroupPropertyName]);
NSNumber * groupType = [group valueForProperty: ALAssetsGroupPropertyType];
Switch ([groupType unsignedIntegerValue]) {
Case ALAssetsGroupAlbum:
{
NSLog (@ "created from my computer or on a device ");
NSString * persistentID = [group valueForProperty: ALAssetsGroupPropertyPersistentID];
If ([[persistentID substringWithRange: nsangefromstring (@ "00000000")] isEqualToString: @ ""])
{
NSLog (@ "my computer ");
}
Break;
}
Case ALAssetsGroupSavedPhotos:
NSLog (@ "camera film ");
Break;
Case ALAssetsGroupPhotoStream:
NSLog (@ "my photo stream ");
Break;
Default:
Break;
}
}
FailureBlock: ^ (NSError * error)
{
NSLog (@ "No groups ");
}];... Remaining full text>