0
-(IBAction)takePhoto:(id)sender
{

    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        imgPicker = [[UIImagePickerController alloc] init];
        imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imgPicker.delegate = self;
        [self presentModalViewController:imgPicker animated:YES];
    }


}

-(IBAction)btnCancelCamera_Clicked:(id)sender{

    [self dismissModalViewControllerAnimated:YES]; 
}




-(IBAction)btnCaptureImage_Clicked:(id)sender{
    [imgPicker takePicture];
}

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

    [self savePhotoProcess:info];


}


-(void)savePhotoProcess:(NSDictionary *)imgObject
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger appcnt = [defaults integerForKey:@"LaunchAmounts"];
    pickedImage = [imgObject objectForKey:UIImagePickerControllerOriginalImage];

    [self dismissModalViewControllerAnimated:YES];

    pickedImage = [self scaleAndRotateImage:pickedImage];



    NSData *imageData = UIImageJPEGRepresentation(pickedImage,0.7);

    imageName = [NSString stringWithFormat:@"image%d.jpg",appcnt];

    [imageArray addObject:imageName];

    path = [SAVEDIMAGE_DIR stringByAppendingPathComponent:imageName];

    [imageData writeToFile:path atomically:YES];






    pickedImage=nil;
    imageData=nil;
    imgPicker=nil;

}



- (UIImage *)scaleAndRotateImage:(UIImage *)image 
{ 
    int width = image.size.width;
    int height = image.size.height;
    CGSize size = CGSizeMake(width, height);

    CGRect imageRect;

    if(image.imageOrientation==UIImageOrientationUp 
       || image.imageOrientation==UIImageOrientationDown) 
            {
        imageRect = CGRectMake(0, 0, width, height); 
            }
    else 
            {
        imageRect = CGRectMake(0, 0, height, width); 
            }

    UIGraphicsBeginImageContext(size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextTranslateCTM(context, 0, height);
    CGContextScaleCTM(context, 1.0, -1.0);

    if(image.imageOrientation==UIImageOrientationLeft) 
            {
        CGContextRotateCTM(context, M_PI / 2);
        CGContextTranslateCTM(context, 0, -width);
            }
    else if(image.imageOrientation==UIImageOrientationRight) 
            {
        CGContextRotateCTM(context, - M_PI / 2);
        CGContextTranslateCTM(context, -height, 0);
            } 
    else if(image.imageOrientation==UIImageOrientationUp) 
            {
            //DO NOTHING
            }
    else if(image.imageOrientation==UIImageOrientationDown) 
            {
        CGContextTranslateCTM(context, width, height);
        CGContextRotateCTM(context, M_PI);
            }

    CGContextDrawImage(context, imageRect, image.CGImage);
    CGContextRestoreGState(context);
    UIImage *img1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return (img1);
}

我的应用程序中有 imagePickerController。客户端测试时它一直在崩溃。我无法模拟该崩溃。请有人告诉导致崩溃的原因是什么,以便我可以模拟该问题。任何帮助都会得到认可。提前致谢。

4

0 回答 0