我正在寻找一种使用Core Image为现有图像添加纯色边框的方法。我已经找到了滤镜列表参考,但没有找到适合的滤镜。
帮帮我吧!
帮帮我吧!
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。对于完整的矩形,您还需要bottomLeft和bottomRight。
覆盖是原始CIImage。
CALayer
为任何 UIView
添加边框(以及圆角、阴影等)。// imgView is an instance of UIImageView, but this works with any UIView
imgView.layer.borderWidth = 2.0f;
imgView.layer.borderColor = [[UIColor blackColor] CGColor];
你还需要 #import <QuartzCore/QuartzCore.h>
并链接到 QuartzCore 框架才能使其工作。