翻转图像无法在iOS 10上运行

时间:2016-09-29 10:37:27

标签: objective-c xcode ios10

iOS 10

中翻转图像时,我遇到了一些奇怪的问题

这是我的代码。

uiImage = [[UIImage alloc] initWithCIImage:ciImage];
flippedImg = [UIImage imageWithCIImage:ciImage scale:uiImage.scale orientation:UIImageOrientationDownMirrored];
captureImgView.image = flippedImg;

我正在接受一个ciImage并将其转入uiImage。 然后翻转UIImage。 此代码适用于所有iOS版本,低于10。 但不适用于10岁及以上。

我尝试了所有方向,

UIImageOrientationUpMirrored
UIImageOrientationLeftMirrored
UIImageOrientationUp
UIImageOrientationRight
UIImageOrientationDown
UIImageOrientationLeft
UIImageOrientationDownMirrored
UIImageOrientationRightMirrored

但没有任何效果。

我从前置摄像头拍摄自拍并将该自拍附加到UIImageView。 我不想附上从前置摄像头拍摄的翻转图像。 我想要这里的原始图像。

请指导我 提前谢谢。

2 个答案:

答案 0 :(得分:2)

我自己得到了解决方案。 我做了什么, 我检查了iOS10版本的系统, 从前置摄像头捕获图像,从CIImage转换为UIImage并将其放在UIImageView上。 我将它放在UIImageView后, 我使用UIImageView轮换CGAffineTransformMakeRotation以适合适当的位置和位置。

这是示例代码。

NSString *systemVersion = [UIDevice currentDevice].systemVersion;
captureImgView = [[UIImageView alloc]init];
if([systemVersion floatValue] < 10.0)
{
    uiImage = [[UIImage alloc] initWithCIImage:ciImage];
    flippedImg = [UIImage imageWithCIImage:ciImage scale:uiImage.scale orientation:UIImageOrientationDownMirrored];
    captureImgView.image = flippedImg;
    captureImgView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
else
{
    uiImage = [[UIImage alloc] initWithCIImage:ciImage];
    flippedImg = [UIImage imageWithCIImage:ciImage scale:uiImage.scale orientation:UIImageOrientationUpMirrored];
    captureImgView.image = uiImage;
    captureImgView.transform = CGAffineTransformMakeRotation ((M_PI * 270 / 180.0));
 }

答案 1 :(得分:0)

我觉得你错过了什么。在我的代码中,它工作得很好......

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imgOriginal;
@property (weak, nonatomic) IBOutlet UIImageView *imgFlipped;

@end

#pragma mark - UIImagePicker delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *uiImage = info[UIImagePickerControllerOriginalImage];
    CGImageRef cgImage = uiImage.CGImage;
    CIImage *ciImage = [CIImage imageWithCGImage:cgImage];

    UIImage *flippedImg = [UIImage imageWithCIImage:ciImage scale:uiImage.scale orientation:UIImageOrientationRight];

    _imgOriginal.image = uiImage;
    _imgFlipped.image = flippedImg;

    [self dismissViewControllerAnimated:YES completion:nil];
}

这里输出:

Flip_Image

在iOS 10中,它会像:

#pragma mark - UIImagePicker delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *uiImage = info[UIImagePickerControllerOriginalImage];
     CGImageRef cgImage = uiImage.CGImage;
    //CIImage *ciImage = [CIImage imageWithCGImage:cgImage];

    //UIImage *flippedImg = [UIImage imageWithCIImage:ciImage scale:uiImage.scale orientation:UIImageOrientationRight];
    UIImage *flippedImg = [UIImage imageWithCGImage:cgImage scale:uiImage.scale orientation:UIImageOrientationLeftMirrored];

    _imgOriginal.image = uiImage;
    _imgFlipped.image = flippedImg;

    [self dismissViewControllerAnimated:YES completion:nil];
}