Objective-C/Cocoa 中的 BitBlt() 等效项

发布于 2024-08-09 10:32:13 字数 212 浏览 5 评论 0原文

几年前,我用 Visual Basic 制作了一个滚动瓷砖 2D 视频游戏。我正在将其翻译为 Mac 版 Cocoa。是否有一个框架允许我使用 BitBlt?或者是否有不使用 OpenGL 的 BitBlt 等效项?谢谢!

I made a scrolling tile 2D video game in visual basic a few years back. I am translating it to Cocoa for the Mac. Is there a framework that would allow me to use BitBlt? Or is there an equivalent to BitBlt without using OpenGL? Thanks!

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

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

发布评论

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

评论(2

倾城泪 2024-08-16 10:32:13

正如 Matt 提到的,您可能需要 CGContextDrawImage 和 CGContextSetBlendMode。

首先,您需要从图像数据创建一个 CGImageRef。您可以通过数据提供商来完成此操作。如果您已经将图像加载到内存中,那么您应该使用CGDataProviderCreateDirect。该数据提供者将是 CGImageCreate 的参数。

接下来,在 Cocoa 视图的 drawRect: 方法中,您需要像这样获取当前上下文:
CGContextRef cgContext = [[NSGraphicsContext currentContext]graphicsPort];

然后使用CGContextDrawImage来绘制图像。

正如 Matt 提到的,您可以使用 CGContextSetBlendMode 控制混合。

As Matt mentioned, you probably want CGContextDrawImage and CGContextSetBlendMode.

First, you need to create a CGImageRef from the image data. You do this with a data provider. If you already have the image loaded in memory, then you should use CGDataProviderCreateDirect. That data provider will be a parameter to CGImageCreate.

Next, in your Cocoa view's drawRect: method, you'll want to get the current context like this:
CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];

Then use CGContextDrawImage to draw the image.

As Matt mentioned, you can control blending with CGContextSetBlendMode.

森林很绿却致人迷途 2024-08-16 10:32:13

您可能应该从核心图形

You should probably start with Core Graphics

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