简体   繁体   中英

Zooming a landscape image captured from camera to use it in portrait

In my app i am capturing image from camera using UIImagePicker and than croping it. But problem is that when I capture image from camera in landscape mode, at the time of croping it in potrait mode the blackbox is shown in image.

Image is captured in landscape mode -

在此输入图像描述

and at the time of using that image the black box is shown at upper and bottom part of image as shown in below image -

在此输入图像描述

but I want to remove that black parts so that image covers whole area.

How can i do this ?

Are you cropping the image with CGImageCreateWithImageInRect([image CGImage], rect); Or else can you share how exactly you are doing the cropping?

When image is taken from the UIImagePickerController in landscape mode, you need to check the orientation property of the UIImage. ie [image orientation];

if the orientation value is UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight , interchange between the rect width and height. And then crop it.

-(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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM