应该反复使用相机崩溃的应用程序?

时间:2010-06-14 20:25:16

标签: iphone memory-management core-data camera

我有一个应用程序可以从用户图像构建幻灯片。他们可以从他们的图书馆抢到或拍照。我发现重复使用从图书馆抓取图像很好。但重复使用拍照会导致不稳定的行为。我一直在崩溃,但大多数情况似乎是在“didFinishPickingMediaWithInfo”之后重新加载视图,这会让事情变得混乱。

我没有泄漏,每张照片拍摄后似乎都正常释放。我正在调整图像大小并将其保存在数据库中。还有其他人遇到这种情况吗?相机的设计是不是经常被称为?

1 个答案:

答案 0 :(得分:0)

抱歉混淆了。它不是连续的,它是拍照,移除和释放相机,然后用户选择选择A,B或C(它们被提示在所有内容上做出选择)然后他们可以拍摄另一张照片,移除和释放相机。 ..etc ...并且在完成所有数据输入时会发生这种情况。

选择相机后,我会调用此代码。我没有在dealloc方法中发布图像选择器。

- (void)openCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{

    imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}

}

在他们“使用”从相机拍摄的照片后,我调用以下代码。它根据图像的原始大小调整图像大小。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *tempCameraImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker dismissModalViewControllerAnimated:YES];

    CGFloat originalSize = tempCameraImage.size.width * tempCameraImage.size.height;
    NSLog(@"Original Size %f", originalSize);
    if (originalSize > 2500000.0) {
        CGSize size = tempCameraImage.size;
        CGRect rect = CGRectMake(0.0, 0.0, .23 * size.width, .23 * size.height);
        UIGraphicsBeginImageContext(rect.size);
        [tempCameraImage drawInRect:rect];
        theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGFloat totalSize = theImage.size.width * theImage.size.height;
        NSLog(@"Final Camera Size %f", totalSize);
        [self resizeImageCamera];
        return;
    }
    else {
        CGSize size = tempCameraImage.size;
        CGRect rect = CGRectMake(0.0, 0.0, .27 * size.width, .27 * size.height);
        UIGraphicsBeginImageContext(rect.size);
        [tempCameraImage drawInRect:rect];
        theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGFloat totalSize = theImage.size.width * theImage.size.height;
        NSLog(@"Final Camera Size %f", totalSize);
        [self resizeImageCamera];
        return;
    }

}

-(void)resizeImageCamera {
if (editingImage1) {
    NSManagedObject *image = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:slideshow.managedObjectContext];
    slideshow.image = image;
    [image setValue:theImage forKey:@"image"];

    CGSize size = theImage.size;
    CGRect rect = CGRectMake(0.0, 0.0, .15 * size.width, .15 * size.height);
    UIGraphicsBeginImageContext(rect.size);
    [theImage drawInRect:rect];
    slideshow.thumbnailImage1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self finishCameraImage];
    return;
}

}

-(void)finishCameraImage {

if (editingImage1) {
    keyInt = @"2";
    [editedObject setValue:keyInt forKey:@"script1"];
    pictureView.alpha = 0;
    self.navigationItem.rightBarButtonItem = nil;
    editedFieldKey = @"line2Int";
    editedFieldName = NSLocalizedString(@"line2Int", @"display name for line2");
    self.title = editedFieldName;
    linePicker.hidden = NO;

}

我意识到我对这张照片做了很多事情。如果我提出几个延迟会有帮助吗?