簡體   English   中英

將iPhone相機中的圖像直接保存到文檔文件夾而不是相機膠卷?

[英]Save image from iPhone camera directly to documents folder and not to camera roll?

我試圖弄清楚如何使用iPhone相機拍攝圖像並將其直接保存到應用程序文檔文件夾中,如果可能的話,不要在相機膠卷中保存。

我有我的應用程序顯示相機,我可以將圖像保存到相機膠卷,但我想將其直接保存到apps文檔文件夾。

任何的想法 ?

謝謝您的幫助。

你可以試試這個- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法:

UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation(pickedImage);

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"imageName.png"];

NSError * error = nil;
[imageData writeToFile:path options:NSDataWritingAtomic error:&error];

if (error != nil) {
    NSLog(@"Error: %@", error);
    return;
}

如果這對您有用,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM