我正在寻找一种使用 Core Image 将纯色边框添加到现有图像的方法。我找到了过滤器列表参考,但没有人制作它。
Help !!
我们需要有要在其中创建实线边框的 CIImage 范围或 CGRect。然后,我们可以在指定区域绘制一个形成实线的CIImage,并针对不同位置重复该步骤3次,以绘制一个完整的实心矩形。下面的代码将在指定区域上方绘制一条实线。
CIImage *overlay1 = [CIImage imageWithColor:[CIColor colorWithRed:255/255.f green:0/255.f blue:0/255.f alpha:1.00f]];
overlay1 = [overlay1 imageByCroppingToRect:image.extent];
overlay1 = [overlay1 imageByApplyingFilter:@"CIPerspectiveTransformWithExtent" withInputParameters:@{@"inputExtent":[CIVector vectorWithCGRect:image.extent],@"inputTopLeft":[CIVector vectorWithCGPoint:CGPointMake(topLeft.x - 5, topLeft.y + 5)],@"inputTopRight":[CIVector vectorWithCGPoint:CGPointMake(topRight.x + 5, topRight.y + 5)],@"inputBottomLeft":[CIVector vectorWithCGPoint:CGPointMake(topLeft.x - 5, topLeft.y )],@"inputBottomRight":[CIVector vectorWithCGPoint:CGPointMake(topRight.x + 5, topRight.y ) ]}];
overlay = [ overlay1 imageByCompositingOverImage:overlay];
我将宽度保留为 5 像素。 topLeft 、 topRight .... 是该位置各自的 CGPoint。对于完整的矩形,您还需要左下角和右下角。
Overlay 是原始的 CIImage 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)