2012-07-01 23 views
6

我正在尋找一種將純色邊框添加到具有Core Image的現有圖像的方法。我找到了過濾器列表引用,但沒有人可以做到。用CIImage添加純色邊框

幫助!!

回答

1

這不正是你問什麼,但它可能會更好,如果你只是想一個邊界(而不是實際繪製邊界到它)來顯示圖像...

您可以使用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框架這個工作。

+0

謝謝jhabbott,但它並沒有幫助我。我正在嘗試修改圖像,而不是僅在其頂部顯示邊框。 – frimoldi

2

我們需要有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。對於一個完整的矩形,你還需要bottomLeft和bottomRight。

覆蓋圖是原始的CIImage。

+0

不確定爲什麼你需要透視變換。爲什麼不剪切線,作爲寬度爲5倍,4倍的矩形。 – user1055568