Scale a landscape image taken from a camera to use it in a portrait

In my application, I take pictures imagewith the camera and use UIImagePickerit to squeeze it. But the problem is that when I shoot the image from the camera in landscape mode, while hacking it in potrait mode, a black box is displayed on the image.

The image is taken in landscape mode -

enter image description here

, and while using this image, a black box is displayed at the top and bottom of the image, as shown in the figure below -

enter image description here

but I want to remove the black parts to imagecover the whole area.

How can i do this?

+5
source share
2 answers

CGImageCreateWithImageInRect([image CGImage], rect); , ?

UIImagePickerController , UIImage. .. [image orientation];

UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight, . .

+3
-(UIImage *)crop:(CGRect)rect Image:(UIImage *)originalImage ImageOrientation:(UIImageOrientation)imageOrientation
{

    CGImageRef imageRef = CGImageCreateWithImageInRect(originalImage.CGImage, rect);

    UIImage *result = [UIImage imageWithCGImage:imageRef scale:1.0f orientation:imageOrientation];

    CGImageRelease(imageRef);

    return result;
}
0

All Articles