0

当我在 iphone 上添加 thre 到四个图像内存后运行这个程序时,警告来了,应用程序崩溃了。所以请帮助我谢谢我只是获取图像参考并写入文件,然后从文件路径获取图像。谢谢

- (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];

}
4

1 回答 1

0

我在模拟器的新应用程序中运行相同的代码,没有崩溃问题或内存警告,它创建了文件。我确实取出了 [app.images count] 并使用了一个局部变量,因为 app.images 没有在此代码中的任何位置设置。因此,如果该变量是垃圾或过度释放,那可能是您的问题。

于 2012-04-06T19:45:16.787 回答