在我的iPhone应用程序中,我需要让用户剪辑用户提供的UIImage
通过给定的动态生成CGPath
.
所有外部给定的(已关闭)CGPath
应该被剪掉,并且生成的图像应该被路径的边界矩形修剪。
图像应使用软边框进行裁剪。也就是说,剪切路径边缘的 Alpha 通道中应该有一个从透明像素到不透明像素的软渐变。
有没有可行的解决方案来达到所描述的效果?
主要问题是如何获得软渐变。我想过光栅化我的CGPath
到蒙版并在光栅化后对其进行模糊处理,但我没有在 iPhone API 中发现任何有关模糊的信息......
至于剪辑,我计划使用CGPathGetBoundingBox
数据,但重新阅读文档告诉我,生成的边界框将包括贝塞尔曲线和二次曲线的控制点,这对我来说是不可接受的。好吧,传统的非零 Alpha 像素图像扫描应该可以完成这项工作。
对于边界框,使用CGPathGetPathBoundingBox
,其中不包括控制点。
您将在 CoreImage 中找到过滤(如模糊)。
CoreImage 过滤器的基本用法(来自https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html#//apple_ref/doc/uid/TP30001185-CH3-TPXREF101 https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html#//apple_ref/doc/uid/TP30001185-CH3-TPXREF101)
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [CIImage imageWithContentsOfURL:myURL];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@0.8f forKey:kCIInputIntensityKey];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGRect extent = [result extent];
CGImageRef cgImage = [context createCGImage:result fromRect:extent];
Filters:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP40004346 https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP40004346
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)