Iphone,如何在图像上添加轮廓?

Jan*_*eng 0 iphone

我想在图像上添加轮廓,你有什么想法吗?注意:我不需要imageview的边框,不需要imageview.layer.borderColor和image.layer.borderWidth;

Ami*_*neG 5

试试这个 :

- (UIImage*)imageWithBorderFromImage:(UIImage*)source;
{
    CGSize size = [source size];
    UIGraphicsBeginImageContext(size);
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    [source drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 1.0, 0.5, 1.0, 1.0); 
    CGContextStrokeRect(context, rect);
    UIImage *testImg =  UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return testImg;
}
Run Code Online (Sandbox Code Playgroud)

来源:http://www.icodesnip.com/snippet/objective-c/add-image-border-to-uiimage