我想提出申請,拍照斷的網站,並將它們保存到NSDocumentDirectory供以後使用。到目前爲止,我的努力失敗了,我想知道如何去做。如何拍攝的圖像關閉一個網站,並把它保存到NSDocumentDirectory
沒有更多的解釋是必要的,但這裏有一些我的(失敗)的嘗試:
一:
NSString *path = @"http://miniwidgit.webs.com/TabRight2.png";
NSFileManager *fmgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [[NSString alloc] initWithFormat:@"%@/File.jpg", documentsDirectory];
NSLog(fileName);
NSError *err;
if ([fmgr copyItemAtPath:path toPath:fileName error:&err])
{}
else
{
NSLog([NSString stringWithFormat:@"%@%@.", @"There was an error. The error was: ", err]);
}
二:
NSURL *path = [NSURL URLWithString:@"http://miniwidgit.webs.com/TabRight2.png"];
NSFileManager *fmgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [[NSString alloc] initWithFormat:@"%@/File.jpg", documentsDirectory];
NSLog(fileName);
NSError *err;
NSString *image = [[NSString alloc] initWithContentsOfURL:path];
[image writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionExternalRepresentation error:&err];
NSLog([NSString stringWithFormat:@"%@%@.", @"There was an error. The error was: ", err]);
一個,我得到了錯誤:
Error Domain=NSPOSIXErrorDomain Code=2 UserInfo=0x3b171b0 "Operation could not be completed. No such file or directory,"
但這沒有任何意義,因爲圖像(在我的si te)存在。
在二,我得到了錯誤:
Error Domain=NSCocoaErrorDomain Code=517 UserInfo=0x3b33090 "Operation could not be completed. (Cocoa error 517.)"
需要很多解釋的,從你所得到的錯誤。 – Nifle 2010-02-24 21:51:43
爲什麼你試圖把圖像變成一個字符串變量?你爲什麼試圖將.png文件保存爲.jpg? – 2010-02-24 22:13:38