我試圖保存和加載從我的應用程序中的相機膠捲拾取的圖像。我得到一個錯誤,當我按下要麼加載或保存按鈕試圖在應用程序錯誤中保存/加載圖像NSInvalidArgumentException
*終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「 - [UIImageView的CGImage]:無法識別的選擇發送到實例0xe637640」
有什麼想法嗎?
AppDelagate的.m
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory i nDomains:NSUserDomainMask] lastObject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
類Im的.M試圖保存/加載圖像
- (IBAction)save:(id)sender {
UIImage *myImage = imageView;
NSData *data = UIImagePNGRepresentation(myImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *appDocsDirectory = [paths objectAtIndex:0];
}
- (IBAction)load:(id)sender {
UIImage *myImage = imageView;
NSData *data = UIImagePNGRepresentation(myImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *appDocsDirectory = [paths objectAtIndex:0];
UIImage* thumImage = [UIImage imageWithContentsOfFile: [NSString stringWithFormat:@"%@/%@.png", appDocsDirectory, @"myNewFile"]];
}
我最初的想法是,你沒有正確標記問題,你沒有包括一個堆棧跟蹤。 – trojanfoe
真的很有幫助謝謝 – JSA986
你似乎並不想幫助自己。你的標籤是錯誤的;他們都無關緊要(有人可以糾正他們,但爲什麼他們呢?)。如果您沒有正確標記問題,那麼正確的人可能會錯過它。在發生異常/崩潰的情況下,爲了找出問題所在,必須有堆棧跟蹤。所以如果你需要幫助,你需要提供更好的信息。 – trojanfoe