2012-02-27 2 views
1

& 버튼을 누르면 현재 주 UIImageView에서 이미지를 저장하는 응용 프로그램을 사진 앨범에 저장하려고합니다.iOS : 현재 UIImageView에서 사진 앨범에 저장하지 못함 - 사진 앨범에 저장할 수 없습니다.

사진 앨범에 저장 버튼을 누르면 프로그램에서 오류가 발생했습니다. 아마 내 코드 구조가 올바르지 않을 것입니다. 아니면 누군가가 올바른 코드 구조를 보여줄 수 있습니까?

여기까지 나의 진도가 있습니다.

-(IBAction) saveToPhotoAlbum{ 

NSString *saveMyPhoto=[NSHomeDirectory() stringByAppendingPathComponent:@"image.png"]; 

UIImage *saved=[UIImage imageWithContentsOfFile:saveMyPhoto]; 

NSData *imageData = [NSData dataWithContentsOfFile:(NSString *)UIImagePNGRepresentation(saved)]; 
[imageData writeToFile:(NSString *)saved atomically:YES ]; 

UIImageWriteToSavedPhotosAlbum(saved, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 



- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo 
{ 
    UIAlertView *alert; 


    if (error) 
     alert = [[UIAlertView alloc] initWithTitle:@"Error" 
              message:@"Unable to save image to Photo Album." 
              delegate:self cancelButtonTitle:@"Ok" 
           otherButtonTitles:nil]; 
    else 
     alert = [[UIAlertView alloc] initWithTitle:@"Success" 
              message:@"Image saved to Photo Album." 
              delegate:self cancelButtonTitle:@"Ok" 
           otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 

답변

0

이미지를 저장하려면 올바른 경로를 지정해야합니다. 하나는 또한 읽고 쓰고, Documents 디렉토리, NSString * docPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]을 확인한 다음 동일한 메서드 -stringByAppendingPathComponent를 사용하여 파일 이름을 추가하거나 두 내용으로 서식이 지정된 문자열을 만듭니다.

+0

감사합니다. Andrea. 첫째, 나는 당신의 방법을 실험하려고 노력할 것입니다. 둘째, 문제가 지속되면 다시 문의하겠습니다. – Amink

+0

위 코드를 수정했지만 동일한 문제가 계속 발생합니다. – Amink

관련 문제