【问题标题】:unwanted distortion: Core image filter is rotating my image不需要的失真:核心图像过滤器正在旋转我的图像
【发布时间】:2012-08-14 03:13:46
【问题描述】:

当我在某些图像上运行核心图像过滤器(如 CIHueAdjust)时,它们会意外旋转 90 度 - 逆时针。这种失真似乎只发生在使用 iOS 设备纵向拍摄的图像上。

这是一个简单的 xcode 项目,其中包含图像导入和 CIHueAdjust 过滤器: owolf.net/uploads/StackOverflow/HueAdjustProject2.zip

如果我对使用 iPhone (like this one linked here) 拍摄的纵向图像运行过滤器,结果类似于下面的屏幕截图。

有解决办法吗?感谢阅读。

【问题讨论】:

    标签: iphone ios xcode image-processing core-image


    【解决方案1】:

    我遇到了同样不受欢迎的轮换问题。

    我通过记住被过滤的 UIImage 的高度是否大于应用过滤器之前的宽度来解决这个问题。

    应用过滤器后,我再次检查 UIImage 的高度是否仍然大于宽度。如果不是,我将 UIImage 旋转了 90 度。

    在确定滤镜已旋转图像后,我在这里使用了扩展来旋转 UIImage。 : Rotating UIImage in Swift

    我使用这个例子在应用过滤器之前和应用过滤器之后获取 UIImage 的高度和宽度: iphone - how can i get the height and width of uiimage

    我进行更正的代码如下所示:

    if heightIsLargerThanWidth && slideShowImageView_2.image!.size.height < slideShowImageView_2.image!.size.width
    {
        self.slideShowImageView_2.image = self.slideShowImageView_2.image?.rotate(radians: .pi/2)
    }
    

    注意 heightIsLargerThanWidth 包含一个布尔值,指示应用过滤器之前的状态。

    【讨论】:

      【解决方案2】:

      您可以使用带有 3 个参数(CIImage、比例、方向 = 右)的 UIIMage.FromImage 函数将图像旋转回原始方向。这是代码sn-p:

      var rotatedCIImage = imageEffectFunc (src); //rotatedCIImage = your CIImage after taken effect that has been rotated 90° counter clockwise.
      
      if (rotatedCIImage != null) {
         UIImage result = UIImage.FromImage(rotatedCIImage,1.0f,UIImageOrientation.Right);
         return result;
      } else {
         return null;
      }
      

      【讨论】:

        【解决方案3】:
        if ([image imageOrientation] == 3) {
            imageView.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
        } else if ([image imageOrientation] == 2) {
            imageView.transform = CGAffineTransformMakeRotation((M_PI / 2.0)*-1);
        }  else if ([image imageOrientation] == 1) {
            imageView.transform = CGAffineTransformMakeRotation(M_PI);    
        }else {
            //no rotation necessary    
        }
        

        【讨论】:

        • 好。感谢您发布解决方案。
        【解决方案4】:

        图像具有不同的方向。应用过滤器后,您将失去方向。您应该使用简单的仿射变换来补偿方向。

        【讨论】:

        • 不正确的解决方案是将原始图像的方向属性复制到调整色调的图像吗?
        • 或者我可以首先忽略方向信息吗?
        猜你喜欢
        • 2010-11-20
        • 2013-09-26
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 2012-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多