Given:
- CGContextRef (
ctx ) with frame {0,0,100,100} - and rect (
r ), with the frame {25,25,50,50}
Itβs easy to copy context into this rectangle:
CGContextClipToRect(ctx, r);
To mask the red area below (red mask):

But I want to invert this cropping rectangle to convert it to a clipping mask . The desired result is to mask the red part below (red mask):

I want to do this programmatically at runtime.
I do not want to manually prepare the bitmap for sending statically with my application.
Given ctx and r , how can this be done at runtime most easily or directly?
source share