核心图片:使用CICrop后,应用合成滤镜无法对齐 [英] Core Image: after using CICrop, applying a compositing filter doesn't line up

查看:60
本文介绍了核心图片:使用CICrop后,应用合成滤镜无法对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CICrop通过裁剪图像的顶部和底部将图像裁剪为一定大小。

I'm using CICrop to crop an image to a certain size by cutting off the top and bottom of the image.

然后,我应用类似CIMultiplyCompositing的方法

Afterwards, I apply something like the CIMultiplyCompositing filter, to combine the cropped image with another image.

两个图像的大小相同,但是结果显示两个图像没有对齐...一个

Both images are the same size, however the result shows that the two images don't line up... one is offset.

所以,我检查了以下内容:

So, I checked the following:

NSLog(@"image after crop: %g, %g, %g, %g", imageToFilter.extent.origin.x,
                       imageToFilter.extent.origin.y,
                       imageToFilter.extent.size.width,
                       imageToFilter.extent.size.height);

NSLog(@"second image: %g, %g, %g, %g", secondImage.extent.origin.x,
                       secondImage.extent.origin.y,
                       secondImage.extent.size.width,
                       secondImage.extent.size.height);

这表明裁剪图像的origin.y具有我所看到的偏移量(结果CICrop的使用):

Which shows that the origin.y of the cropped image has the offset I'm seeing (a result of using CICrop):

image after crop: 0, 136, 3264, 2176
second image: 0, 0, 3264, 2176

所以,有什么办法让我重置裁剪后的图像范围 ,因此origin.y为零?检查文档中的CIImage,范围是只读属性。

So, is there any way for me to reset the cropped images "extent" rect, so that origin.y is zero? Checking the docs for CIImage, "extent" is a read only property.

或者我是否必须做一些效率低下的转换,才能转换为其他图像类型/原始数据,并且然后返回CIImage?

Or am I going to have to do some horribly inefficient conversion to another image type/raw data and then back to a CIImage?

谢谢您的建议。

推荐答案

我想出了答案...这很简单。我只需要在裁剪后在CIImage上应用转换变换,就像这样:

I figured out the answer to this... and it's an easy one. I just needed to apply a "Translation" transform on the CIImage after cropping it, like so:

imageToFilter = [imageToFilter imageByApplyingTransform:CGAffineTransformMakeTranslation(0, -imageToFilter.extent.origin.y)];

这实际上将y的原点移回了0。

That effectively moves its y origin back to 0.

这篇关于核心图片:使用CICrop后,应用合成滤镜无法对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆