我试图在我的应用程序中保存和加载从相机胶卷中挑选的图像。当我按下加载或保存按钮时出现错误
*由于未捕获的异常“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];
我试图保存/加载图像的类的.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"]];
}