使用CIImage添加纯色边框 [英] Add solid color border with CIImage

查看:48
本文介绍了使用CIImage添加纯色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用Core Image将纯色边框添加到现有图像的方法.我找到了过滤器列表参考,但是没有人可以参考.

I'm looking for a way to add a solid color border to an existent image with Core Image. I've found the filter list reference but there is no one to make it.

帮助!!

推荐答案

我们需要具有要在其中创建实心边框的CIImage范围或CGRect.然后,我们可以在指定区域绘制一条形成实线的CIImage,然后针对不同位置重复执行3次以上的步骤以绘制一个完整的实心矩形.以下是一段代码,它将在指定区域上方绘制一条实线.

We need to have the CIImage extent or the CGRect in which we want to create the solid border. Than, We can draw a CIImage forming a solid line in the specified area, and repeat the steps for 3 more times for different positions to draw a complete solid rectangle. Following is the piece of code which will draw a straight solid line above the specified area.

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.

I have kept the width for 5 pixels. topLeft , topRight.... are the respective CGPoint for the position. For a complete rectangle you will also need bottomLeft and bottomRight.

叠加层是原始CIImage.

Overlay is the original CIImage .

这篇关于使用CIImage添加纯色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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