本文介绍了如何从PHAsset获取原始图像和媒体类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 ** GMImagePickerController **
返回照片应用中所选图片的列表。
My **GMImagePickerController**
returns the list of selected images from photos app.
代码为如下所示。
- (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickingAssets:(NSArray *)assetArray
{
NSLog(@"%@",assetArray);
NSLog(@"GMImagePicker: User ended picking assets. Number of selected items is: %lu", (unsigned long)assetArray.count);
}
像这样的assetArray返回结果,我从照片应用中选择了3张图片
The assetArray return result like this, I selected 3 images from photos app
(
"<PHAsset: 0x7fa39e02e840> 1AEEF04A-F8AB-4019-AAB5- 2875CFD8F8E3/L0/001 mediaType=1/0, sourceType=1, (425x425), creationDate=2016-02-03 13:53:17 +0000, location=0, hidden=0, favorite=0 ",
"<PHAsset: 0x7fa39e02c840> 50489C13-55D0-4518-B290-B01B99D66996/L0/001 mediaType=1/0, sourceType=1, (425x335), creationDate=2016-02-03 13:53:08 +0000, location=0, hidden=0, favorite=0 ",
"<PHAsset: 0x7fa39e02c750> D0A466B2-9CF2-4FD9-A12F-07921A1D0E8F/L0/001 mediaType=1/0, sourceType=1, (425x365), creationDate=2016-02-03 13:53:04 +0000, location=0, hidden=0, favorite=0 "
)
现在的问题是我想从上面的结果中获取 OriginalImage
和 mediaType
将图像存储到文档目录中。
请帮我解决这个问题。
Now the problem is I want to get OriginalImage
and mediaType
from above result to store image into document directory.Please help me to solve this problem.
推荐答案
要检查媒体类型,你可以使用phasset的以下属性
To check media type you can use the following property of phasset
if asset.mediaType == .image{
//do anything for image asset
}else if asset.mediaType == .video{
//do anything for video asset
}else if asset.mediaType == .audio{
//do anything for audio asset
}
要从PHAsset获取原始图像,您可以执行以下操作:
To get the original image from PHAsset you can do the following:
let requestImageOption = PHImageRequestOptions()
requestImageOption.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat
let manager = PHImageManager.default()
manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode:PHImageContentMode.default, options: requestImageOption) { (image:UIImage?, _) in
// process the original image
}
这篇关于如何从PHAsset获取原始图像和媒体类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!