开发者

Quartz 2D: draw from a CGContext to another CGContext

开发者 https://www.devze.com 2023-01-03 17:30 出处:网络
I开发者_如何学C have a CGBitmapContext (bitmapContext) and I would like to draw some rectangle part (rect) of it to the current CGContext (context).

I开发者_如何学C have a CGBitmapContext (bitmapContext) and I would like to draw some rectangle part (rect) of it to the current CGContext (context).

Right now I do that way:

CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
CGContextClipToRect(context, rect);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
CGImageRelease(cgImage);

Is it optimal? What is the best way to do it?


The alternative seems to be to create a sub-image, which I can only imagine to be less optimal.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号