2011-11-10 11 views
20

私の前の質問hereに関連しています。ファイルパスから資産ライブラリへの画像をUIImageに読み込みます。

私は、たとえば、資産ライブラリ内の画像へのパスを持っている:

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

、どのように私はこのパスから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]; 
} 

答えて

18

上記の私のコメントにリンクさ答えから:あなたはまた、あなたを得るために[myasset aspectRatioThumbnail]を使用することができます

-(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]; 
    } 
} 
12

は、以下のことを試してみてください。 (UIImage *)imageWithContentsOfFile:(NSString *)path

0

画像。

関連する問題