UIImagePickerController的视图尺寸错误

4
我正在使用UIImagePickerControllerUIView作为我自己UIViewController的子视图。当我拍照时,会出现问题。具体表现如下:
1. 我从UIImagePickerController的视图中看到的图片是这样的: enter image description here 2. 当我拍照并将其放在UIImageView上时,我看到的是这个: enter image description here 从我的观察中可以看出,拍出来的图片在Y轴上稍微高了一点。有没有什么办法解决这个问题?如果必要,我可以在输出的图片上使用某种剪裁方式。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

因为我在UIImageViewcontentMode中使用了UIViewContentModeScaleAspectFill,所以我可以理解这种行为,但我希望能够指定从哪个Y轴开始进行“查看”。

1个回答

4

28分钟后终于搞定了,哦,好吧,下面是解决方法:

CGImageRef imageRef = CGImageCreateWithImageInRect([imageTaken CGImage], CGRectMake(0.0f, 0.0f, 960.0f, 960.0f));

[selectedImageView setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);

通过在960.0f处裁剪,我可以保持图片的原始质量,并且能够从哪个Y轴上进行“切割”。我还添加了这个:
+ (UIImage*)rotate:(UIImage*)image andOrientation:(UIImageOrientation)orientation;
{
    UIGraphicsBeginImageContext(image.size);

    CGContextRef context=(UIGraphicsGetCurrentContext());

    if (orientation == UIImageOrientationRight) {
        CGContextRotateCTM (context, 90/180*M_PI) ;
    } else if (orientation == UIImageOrientationLeft) {
        CGContextRotateCTM (context, -90/180*M_PI);
    } else if (orientation == UIImageOrientationDown) {
        // NOTHING
    } else if (orientation == UIImageOrientationUp) {
        CGContextRotateCTM (context, 90/180*M_PI);
    }

    [image drawAtPoint:CGPointMake(0, 0)];
    UIImage *img=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

因为图片向左旋转。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接