iOS拍照后使用该图片(获取照片的ALasset传到相册)
程序员文章站
2024-01-15 19:18:46
...
问题:
拍照后,点击选择照片在-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 的代理方法中获取了相册的Alasset后,发现为空
解决办法:
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:@"public.image"])
{
//先把图片转成NSData
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
// TODO: error handling
} else {
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
[self.selectPhotos addObject:asset];
[_imageCollection reloadData];
} failureBlock:^(NSError *error) {
}];
}
}];
}
}
上一篇: 透明状态栏和导航栏设置
下一篇: PHP通过文件路径获取文件名的实例代码