Quartz 2D:从一个 CGContext 绘制到另一个 CGContext

发布于 2024-09-05 17:01:42 字数 451 浏览 1 评论 0原文

我有一个 CGBitmapContext (bitmapContext),我想将它的一些矩形部分 (rect) 绘制到当前 CGContext (context)。

现在我这样做:

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

这是最佳的吗?最好的方法是什么?

I 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝咒 2024-09-12 17:01:42

另一种选择似乎是创建一个子图像,我只能想象这不太理想。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文