简体   繁体   中英

How to delete a rect in a UIImage on iOS?

How can i delete a rect area in a UIImage? My idea is i got a Solid colour image and a CGRect rectangle and i would like to deleted the CGrect in the UIImage so that the CGRect area will be transparent. Please refer to the image below. The Semi-red is my uiimage and i would like to deleted the middle rect so that it is transparent for me to view the background image.

例

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM