Objective-C/Cocoa 中的 BitBlt() 等效项
几年前,我用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Matt 提到的,您可能需要 CGContextDrawImage 和 CGContextSetBlendMode。
首先,您需要从图像数据创建一个 CGImageRef。您可以通过数据提供商来完成此操作。如果您已经将图像加载到内存中,那么您应该使用
CGDataProviderCreateDirect
。该数据提供者将是 CGImageCreate 的参数。接下来,在 Cocoa 视图的
drawRect:
方法中,您需要像这样获取当前上下文:CGContextRef cgContext = [[NSGraphicsContext currentContext]graphicsPort];
然后使用
CGContextDrawImage
来绘制图像。正如 Matt 提到的,您可以使用 CGContextSetBlendMode 控制混合。
As Matt mentioned, you probably want
CGContextDrawImage
andCGContextSetBlendMode
.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 useCGDataProviderCreateDirect
. That data provider will be a parameter toCGImageCreate
.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
.您可能应该从核心图形
You should probably start with Core Graphics