'writeToFile'에 해당되는 글 1건

 
  1. 2010.07.23 [iPhone/Xcode] 어플 도큐먼트에 이미지 파일 저장/로드 2
2010. 7. 23. 17:34 ANDROID IOS
[iPhone/Xcode] 어플 도큐먼트에 이미지 파일 저장/로드

앱 자체에 이미지를 저장하고 로드하는 방법입니다.

각각의 앱에는 지정된 도큐먼트 디렉토리가 할당됩니다.

디렉토리를 얻어오고 파일명을 지정하여 저장/로드 하는 코드입니다.



경로형식 /Users/kaudo/Library/Application Support/iPhone Simulator/4.0.1/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents/


이미지 저장

NSArray *aryPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *strPathBackground=[NSString stringWithFormat:@"%@/kaudo.jpg",[aryPath objectAtIndex:0]];

NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(imgBackground,80)];

[imageData writeToFile:strPathBackground atomically:YES];


이미지 로드

NSArray *aryPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *strPathBackground=[NSString stringWithFormat:@"%@/kaudo.jpg",[aryPath objectAtIndex:0]];

imageView.image=[[UIImage allocinitWithContentsOfFile:strPathBackground];



최근에 올라온 글

최근에 달린 댓글