【问题标题】:UIImage sideway after converting it from CIImage从 CIImage 转换后的 UIImage 横向
【发布时间】:2014-01-06 13:42:56
【问题描述】:

我在 UIImage 上应用过滤器,但转换后,它显示为横向。下面是我的代码。

CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess];

CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectChrome"
                                              keysAndValues:kCIInputImageKey, ciImage, nil];
[filter setDefaults];

CIContext *context = [CIContext contextWithOptions:nil];
CIImage *outputImage = [filter outputImage];

CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];

UIImage *newImage = [[UIImage alloc]initWithCIImage:outputImage];

它在 newImage 和维度中成功渲染,但图像是侧面的。上面的代码中是否有任何地方导致方向改变?

【问题讨论】:

    标签: ios iphone cocoa-touch core-graphics cgcontext


    【解决方案1】:

    在应用滤镜之前将图像缩放到正确的方向。

    点击此链接:https://stackoverflow.com/q/538064/871102

    代替:

    CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess];
    

    写:

    UIImage *properOrientedImage = [self scaleAndRotateImage:self.imgToProcess];
    
    CIImage *ciImage = [[CIImage alloc] initWithImage:properOrientedImage.CGImage];
    

    【讨论】:

      【解决方案2】:

      是的,您可以考虑设置图像方向以确保使用以下方法初始化UIImage

      - (id)initWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
      

      你有几个图像方向:

      typedef enum {
         UIImageOrientationUp,
         UIImageOrientationDown,   // 180 deg rotation
         UIImageOrientationLeft,   // 90 deg CW
         UIImageOrientationRight,   // 90 deg CCW
         UIImageOrientationUpMirrored,    // as above but image mirrored along
         // other axis. horizontal flip
         UIImageOrientationDownMirrored,  // horizontal flip
         UIImageOrientationLeftMirrored,  // vertical flip
         UIImageOrientationRightMirrored, // vertical flip
      } UIImageOrientation;
      

      Up 是默认值 - 所以尝试旋转它。

      【讨论】:

      • 我们在谈论 CIIimage
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多