Rear iPhone 4 camera too high quality for UIImageView?
When using the iPhone 4, I'm having memory issues when using the rear-facing camera. It's causing memory errors and won't assign the picture to a UIView. Here's the code.
-(IBAction)getCameraPicture:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
if(sender == takePictureButton)
pick开发者_C百科er.sourceType = UIImagePickerControllerSourceTypeCamera;
else
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissModalViewControllerAnimated:YES];
}
It works fine when using the front-facing (lower quality) camera, as does loading existing pictures not taken at full quality. Is there any way to reduce the quality of the photo taken with the rear camera, or some other way to get around this issue?
This is a common problem, the images from the cameras on the iPhone are huge! Usually much bigger than you need. Best practice is to resize the image to be no bigger than you need. I use MGImageUtilities and it works great.
If you need the full-sized image for any reason, cache it to disk before you resize it.
精彩评论