缩放从相机捕获的风景图像,以纵向使用它

时间:2012-07-05 11:36:15

标签: iphone objective-c ios ios5 camera

在我的应用中,我使用image从相机捕获UIImagePicker而不是裁剪。但问题是,当我在横向模式下从相机捕捉图像时,在以画面模式裁剪时,黑框显示在图像中。

以横向模式捕获图像 -

enter image description here

在使用该图像时,黑框显示在图像的上部和下部,如下图所示 -

enter image description here

但我想删除那些黑色部分,以便image覆盖整个区域。

我该怎么做?

2 个答案:

答案 0 :(得分:3)

你是否正在裁剪图像 CGImageCreateWithImageInRect([image CGImage], rect); 或者你可以分享一下你在裁剪的确切方式吗?

在横向模式下从UIImagePickerController拍摄图像时,需要检查UIImage的方向属性。即[image orientation];

如果方向值为UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight,则在矩形宽度和高度之间互换。然后裁剪它。

答案 1 :(得分:0)

-(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;
}
相关问题