【发布时间】:2014-11-06 14:00:28
【问题描述】:
我有一个带有图像的 UIImageView,它是一辆具有透明背景的汽车:
我想在汽车周围画一个边框:
我怎样才能达到这个效果?
目前,我已经以这种方式测试过CoreGraphics,但没有很好的结果:
// load the image
UIImage *img = carImage;
UIGraphicsBeginImageContext(img.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor redColor] setFill];
CGContextTranslateCTM(context, 0, img.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, img.size.width * 1.1, img.size.height*1.1);
CGContextDrawImage(context, rect, img.CGImage);
CGContextClipToMask(context, rect, img.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context,kCGPathFill);
// generate a new UIImage from the graphics context we drew onto
UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
有什么帮助吗?谢谢。
【问题讨论】:
标签: ios xcode image uiimageview draw