向UIImage添加图像边框

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了向UIImage添加图像边框相关的知识,希望对你有一定的参考价值。

Adds a fine border to a UIImage.
  1. - (UIImage*)imageWithBorderFromImage:(UIImage*)source;
  2. {
  3. CGSize size = [source size];
  4. UIGraphicsBeginImageContext(size);
  5. CGRect rect = CGRectMake(0, 0, size.width, size.height);
  6. [source drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
  7.  
  8. CGContextRef context = UIGraphicsGetCurrentContext();
  9. CGContextSetRGBStrokeColor(context, 1.0, 0.5, 1.0, 1.0);
  10. CGContextStrokeRect(context, rect);
  11. UIImage *testImg = UIGraphicsGetImageFromCurrentImageContext();
  12. UIGraphicsEndImageContext();
  13. return testImg;
  14. }

以上是关于向UIImage添加图像边框的主要内容,如果未能解决你的问题,请参考以下文章

Objective- C:在 UIImage 上绘制边框

添加边框到UIImages内存问题

Swift iOS 为 UIImage 添加隐形边框

如何在 uiimage 选择器控制器中更改图像大小

使用 SVG 过滤器向 SVG 图像元素添加边框 [重复]

如何使用命令行工具向图像添加透明的 OS X 样式边框?