下面的两条语句都有效。但第二条语句给了我EXC_BAD_ACCESS。imageWithContentsOfFile会导致EXC_BAD_ACCESS
UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:photoFilenameNoPath], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
UIImageWriteToSavedPhotosAlbum([UIImage imageWithContentsOfFile:filenameWithPath], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
我跟踪它归结为[image autorelease]
在:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
NSString *alertTitle;
NSString *alertMessage;
if (error == nil) {
// Display UIAlertView to tell user that photo have been saved
alertTitle = @"Photo Saved";
alertMessage = @"";
}
else {
// Display UIAlertView with error string to tell user that photo have NOT been saved
alertTitle = @"Photo Not Saved";
alertMessage = [NSString stringWithFormat:@"ERROR SAVING:%@",[error localizedDescription]];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[image autorelease];
}
我需要使用imageWithContentsOfFile
,因为我的一些文件在文档文件夹中,还有一些是在主束。
如果我使用imageWithContentsOfFile
而不是imageNamed
,任何人都可以帮助解释为什么我不需要发布image
?
非常感谢。