2012-03-09 2 views

답변

1

는 이미지가

//Where the 0 denotes the compression (0 to 1). 
NSData *imageData = UIImageJPEGRepresentation(image, 0); 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder 
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"MyImageFolder"]; 

NSError *error; 
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) 
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder 

NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", imageName]]; //add our image to the path 

bool successI = [imageData writeToFile:fullPath atomically:YES]; 
if (successI) { 
    //  NSLog(@"Image saved correctly"); 
} else 
    NSLog(@"Error while saving Image"); 

언급하고 잊어 버렸 이미지라고 가정하면, 당신은 다른 곳에 저장하는

NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

을 변경할 수 있습니다.

1

먼저 다음 앱에서 문서 또는 라이브러리 폴더에 데이터를 기록

UIImageJPEGRepresentation 

또는

UIImagePNGRepresentation 

가있는 NSData에있는 UIImage을 변환 할 수 있습니다.

관련 문제