将文件path中的图像加载到资产库中

与我之前的问题有关。

我有一个path到资产库中的图像,例如:

assets-library://asset/asset.JPG?id=1000000001&ext=JPG 

现在,我怎么能从这个path的图像加载到UIImage对象?

这里是代码:

 NSString *path = [occasion imagePath]; //temp NSLog(@"the 2nd occasion imagePath is: %@", path); //end if (path != nil) { //UIImage *image = [UIImage imageNamed:path]; UIImage *image = [UIImage imageWithContentsOfFile:path]; image = [image imageByScalingAndCroppingForSize:CGSizeMake(36.0, 42.0)]; [[cell imageView] setImage:image]; } 

从我上面的评论中链接的答案:

  -(void)findLargeImage { NSString *mediaurl = [self.node valueForKey:kVMMediaURL]; // ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation *rep = [myasset defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; if (iref) { largeimage = [UIImage imageWithCGImage:iref]; [largeimage retain]; } }; // ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) { NSLog(@"booya, cant get image - %@",[myerror localizedDescription]); }; if(mediaurl && [mediaurl length] && ![[mediaurl pathExtension] isEqualToString:AUDIO_EXTENSION]) { [largeimage release]; NSURL *asseturl = [NSURL URLWithString:mediaurl]; ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease]; [assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock]; } } 

尝试以下操作: (UIImage *)imageWithContentsOfFile:(NSString *)path

你也可以使用[myasset aspectRatioThumbnail]来获得你的图像。

Interesting Posts