我有一张来自相机胶卷的NSURL
照片,我想加载图片或NSData
。
我试试这个:
NSData *imageDataTemp = [NSData dataWithContentsOfURL:path];
但它返回图像大小的一半。
答案 0 :(得分:1)
以下是如何加载具有ALAsset
网址的图片。
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *asset)
{
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef image = [representation fullResolutionImage];
if (image)
{
yourImageView.image = [UIImage imageWithCGImage:image];
}
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error)
{
NSLog(@"Error %@", [error localizedDescription]);
};
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:resultBlock
failureBlock:failureBlock];
NSURL *yourALAssetURL;
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[yourALAssetURL] options:nil];
PHAsset *asset = result.firstObject;
if (asset)
{
PHCachingImageManager *imageManager = [[PHCachingImageManager alloc] init];
// Request an image for the asset from the PHCachingImageManager.
[imageManager requestImageForAsset:asset
targetSize:CGSizeMake(100.0f, 100.0f)
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *image,
NSDictionary *info)
{
NSLog(@"IMAGE: %@", image);
}];
}
Apple创建了一个使用PHPhotoLibrary的示例应用程序。它可用here。