ios - CoreImage CICrop 返回 0x0 像素图像

标签 ios crop cgimage core-image

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

我有一个 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 而不是 CIImage。我宁愿不必转换,因为我计划在裁剪后做其他 CoreImage 的东西。

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

有什么想法吗?

干杯。

最佳答案

最后我放弃了 Core Image 的裁剪,转而使用它:

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

    UIImage *cropped = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);

    return cropped;
}

关于ios - CoreImage CICrop 返回 0x0 像素图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10553321/

相关文章:

iphone - 索引在 TableView 中不起作用

ios - 当应用程序在后台时更新 iOS Cordova WebView

ios - 从 CGImageRef 获取像素数据包含额外的字节?

swift - 从 MTLTexture 制作 CGImage 时出现内存泄漏(Swift、macOS)

ios - 不断刷新UIImageView IOS背景图

ios - Xcode 6 iPair Air 无法在设备上运行应用程序(操作系统版本)

ffmpeg - MPV(FFmpeg)堆叠2个视频,然后在不重新编码的情况下裁剪输出?

android.os.TransactionTooLargeException 与裁剪 Activity

css - 在 div 内裁剪居中图像

ios - 在使用CGImageDestinationFinalize时如何避免malloc