使用设备库中的文件名初始化 UIImageView
Initialize UIImageView with a file name from the device library
我有一张名为 IMG_0094.JPG 的照片,由设备的相机拍摄。
我想用它初始化我的 UIImageView
,但我的代码不起作用。
以下代码在viewDidLoad
中。
currentImageName = [contact objectForKey:@"image"];
NSURL* aURL = [NSURL URLWithString:currentImageName];
NSLog(@"%@", aURL);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:aURL resultBlock:^(ALAsset *asset)
{
UIImage *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.5 orientation:UIImageOrientationUp];
UIImageView *photo = (UIImageView *)[self.view viewWithTag:TAG_PHOTO];
photo.image = copyOfOriginalImage;
photo.contentMode = UIViewContentModeScaleAspectFit;
}
failureBlock:^(NSError *error)
{
// error handling
NSLog(@"failure---");
}];
我的 NSLOG return 2015-02-26 10:39:54.899 Fiche 联系人[1600:60b] IMG_0094.JPG
我有一张名为 IMG_0094.JPG 的照片,由设备的相机拍摄。
我想用它初始化我的 UIImageView
,但我的代码不起作用。
以下代码在viewDidLoad
中。
currentImageName = [contact objectForKey:@"image"];
NSURL* aURL = [NSURL URLWithString:currentImageName];
NSLog(@"%@", aURL);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:aURL resultBlock:^(ALAsset *asset)
{
UIImage *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.5 orientation:UIImageOrientationUp];
UIImageView *photo = (UIImageView *)[self.view viewWithTag:TAG_PHOTO];
photo.image = copyOfOriginalImage;
photo.contentMode = UIViewContentModeScaleAspectFit;
}
failureBlock:^(NSError *error)
{
// error handling
NSLog(@"failure---");
}];
我的 NSLOG return 2015-02-26 10:39:54.899 Fiche 联系人[1600:60b] IMG_0094.JPG