Hi guys,
I have a kind of funny problem..
What my program does:
first I can take a pic with the camera --> then it gets gropped --> after that it sould be displayed correctly on a UIImageView
The problem is that the image displayed on the imageview is mirrored and turned.. I dont know why but I hope someone does ^^
If I delete the part where it gets cropped, the image gets displayed correctly on the imageview. It seems that my cropping method is turning the image around.
Here is my code:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.view addSubview:mainView];
UIImage *camImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *croppedImage = [self imageByCropping:camImage toRect:CGRectMake(1, 1,150, 160)];
[mainView.imageView setImage:croppedImage];
NSLog([NSString stringWithFormat:@"%f°", croppedImage.size.height]);
//NSLog("Cropped Image size y %.02f", croppedImage.size.height);
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
//[croppedImage release];
//[camImage release];
}
- (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect {
UIGraphicsBeginImageContext(rect.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect clippedRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
CGContextClipToRect( currentContext, clippedRect);
CGRect drawRect = CGRectMake(rect.origin.x,
rect.origin.y,
imageToCrop.size.width,
imageToCrop.size.height);
CGContextDrawImage(currentContext, drawRect, imageToCrop.CGImage);
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return cropped;
[cropped release];
//CGContextRelease(currentContext);
}
I took two screenshots so that you can get into my problem..
Thats the cam view, exactly this pic will be shot by the camera:
With the cropping method, the imageview looks like that:
Without cropping:
By the way, do you see the little black gap between the cameraview an the black toolbar?
How can i get that away?
You may excuse any mistakes in my english language..
Thanx,
Robin R.