2011-11-10 2 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

: 여기

코드입니다

-(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

또한 얻을 [myasset aspectRatioThumbnail]을 사용할 수 있습니다 당신의 영상.

관련 문제