簡體   English   中英

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

[英]How to delete a rect in a UIImage on iOS?

如何刪除UIImage中的矩形區域? 我的想法是我得到了一個純色圖像和一個CGRect矩形,我想刪除UIImage中的CGrect,以便CGRect區域是透明的。 請參考下圖。 半紅色是我的uiimage,我想刪除中間的rect,以便對我來說查看背景圖像是透明的。

例

CGContextClearRect(上下文,your_rect)

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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM