当我在iphone上运行这个程序后添加四个图像内存警告来应用程序崩溃。所以请帮助我谢谢我只是获取图像参考并写入文件,然后从文件路径获取图像。感谢
- (IBAction)addPicsButtonClick:(id)sender
{
UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathToDocuments=[paths objectAtIndex:0];
AppDelegate *app = [[UIApplication sharedApplication] delegate];
NSData *imageData = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 0.3f);
[imageData writeToFile:[NSString stringWithFormat:@"%@/%d.jpg", pathToDocuments, [app.images count]] atomically:YES];
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:0)
我在模拟器中的新应用程序中运行相同的代码,并且没有崩溃问题或内存警告,并且它创建了文件。我确实取出[app.images count]并使用了局部变量,因为app.images没有在此代码中的任何位置设置。因此,如果该变量是垃圾或过度释放,那可能是您的问题。