以下代码获取当前屏幕的 UIImage:
UIGraphicsBeginImageContext(self.view.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
如果我有一个 CGRect 矩形并且我只想获取该矩形中当前屏幕的 UIImage,我该怎么办?