-(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。当客户端测试时它会一直崩溃。我无法判断崩溃。有人告诉导致崩溃的原因是什么,所以我可以模拟这个问题。任何帮助都会被贬低。谢谢提前。