【问题标题】:CoreImage CICrop returning 0x0 pixel imageCoreImage CICrop 返回 0x0 像素图像
【发布时间】:2012-05-11 14:28:14
【问题描述】:

抱歉今天问了这么多问题,周五出现脑死症状。

我有一个 CICrop 过滤器:

[crop setValue:beginImage forKey:@"inputImage"];  //give the crop filter the beginImage
    [crop setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:_exportSize W:_exportSize] forKey:@"inputRectangle"];  //give the filter the size to crop to
    croppedImage = [crop valueForKey:@"outputImage"];  //set the output image, note it's still a CIImage at this point

很遗憾,它不起作用。它裁剪的图像最终为 0x0 像素。 _exportSize(它是一个 CGFloat)的快速 NSLog 显示它是 1024,但日志显示图像裁剪后是 0x0。我不知道为什么。

此代码以前有效。我认为唯一的区别是我曾经裁剪 UIImage 而不裁剪 CIImages。我宁愿不必转换,因为我计划在裁剪后做其他 CoreImage 的东西。

正如我所说,_exportSize 是一个 CGFloat _exportSize;并记录它显示它 1024.0000。

有什么想法吗?

干杯。

【问题讨论】:

    标签: ios crop cgimage core-image


    【解决方案1】:

    最后我放弃了使用 Core Image 进行裁剪并改用它:

        -(UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
    {
        CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
    
        UIImage *cropped = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
    
        return cropped;
    }
    

    【讨论】:

      【解决方案2】:

      试试

      [crop setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:_exportSize.width W:_exportSize.height] forKey:@"inputRectangle"];

      而不是

      [crop setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:_exportSize W:_exportSize] forKey:@"inputRectangle"];

      帮助网址http://gigliwood.com/weblog/Cocoa/Core_Image,_part_2.html

      Z 应该是宽度
      W应该是高度

      希望对你有帮助。

      【讨论】:

      • 你好。 _exportSize 是一个 CGFloat,它没有宽度或高度属性。但感谢发帖。我不知道问题出在哪里。
      猜你喜欢
      • 2013-01-06
      • 2011-12-25
      • 2012-05-08
      • 2015-11-03
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      相关资源
      最近更新 更多