2013-02-25 74 views
1

嗨,我是iPhone環境新手。我正在使用Xcode 4.5。我正在開發相機應用程序。我想將從相機拍攝的圖像保存到文檔目錄中的單獨文件夾中,並且也保存在照片庫中的自定義相冊中。我將圖像保存到照片庫中的自定義相冊中,但我不知道如何保存到文檔目錄...任何人都可以告訴我如何做到這一點..?將攝像頭捕獲的圖像保存到ios的文檔目錄中

回答

12

嘗試

UIImage *image = [UIImage imageNamed:@"Image.jpg"]; 
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"New Folder"]; 
// New Folder is your folder name 
NSError *error = nil; 
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath]) 
    [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error]; 

NSString *fileName = [stringPath stringByAppendingFormat:@"/image.jpg"]; 
NSData *data = UIImageJPEGRepresentation(image, 1.0); 
[data writeToFile:fileName atomically:YES]; 
+0

感謝您response..I嘗試這種代碼的工作,但如果我一定要看到圖像,檢查圖像尺寸..? – Parimala 2013-02-25 10:20:24

+0

請嘗試以下路徑:Finder - > Go - >轉到文件夾 - >/Users/GirishS/Library/Application Support/iPhone Simulator。用系統名稱替換GirishS。 – Girish 2013-02-25 10:26:48

+0

在應用程序支持,它不顯示iPhone模擬器..! – Parimala 2013-02-25 10:46:07