如何在 iOS 上删除 UIImage 中的矩形?

Posted

技术标签:

【中文标题】如何在 iOS 上删除 UIImage 中的矩形?【英文标题】:How to delete a rect in a UIImage on iOS? 【发布时间】:2012-04-30 09:55:10 【问题描述】:

如何删除 UIImage 中的矩形区域?我的想法是我有一个纯色图像和一个 CGRect 矩形,我想删除 UIImage 中的 CGrect,以便 CGRect 区域是透明的。请参考下图。半红色是我的 uiimage,我想删除中间的矩形,以便我可以透明地查看背景图像。

【问题讨论】:

【参考方案1】:
UIImage *yourImage;
CGRect imageRect = CGRectMake(0, 0, yourImage.size.width, yourImage.size.height);
CGRect grayRect = CGRectMake(20, 20, 20, 20);
CGRect rects[2] = 
  imageRect,
  grayRect
;
CGContextClipToRects(context, rects, 2);
[yourImage drawInRect:imageRect];

【讨论】:

【参考方案2】:

CGContextClearRect(context, your_rect)

【讨论】:

以上是关于如何在 iOS 上删除 UIImage 中的矩形?的主要内容,如果未能解决你的问题,请参考以下文章