【问题标题】:UIImagePickerController's view with wrong sizeUIImagePickerController 视图大小错误
【发布时间】:2013-10-19 20:33:08
【问题描述】:

我使用UIImagePickerControllerUIView 作为我自己的UIViewController's UIView 子视图的子视图。没什么特别的,当我拍照时问题就来了。正在发生的事情是这样的:

1 我从UIImagePickerController 的视图中看到的图片是这样的:

2 这是我拍照时看到的([self.imagePicker takePicture]; ) 并将其放在UIImageView:

据我所见,输出的图像在 Y 轴上有点高。有没有办法解决这个问题?我不在乎是否必须对以下出现的图像进行某种裁剪:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

当我在UIImageView contentMode 上使用UIViewContentModeScaleAspectFill 时,我可能会理解这种行为,但我希望能够从我想要开始“查看”的位置指定 Y。

【问题讨论】:

    标签: ios uiimageview uiimage uiimagepickercontroller


    【解决方案1】:

    能够在 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;
    }
    

    因为图片正在向左旋转。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多