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!
Asked
Active
Viewed 2,446 times
2 Answers
3
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
.

Doug Richardson
- 10,483
- 6
- 51
- 77
2
You should probably start with Core Graphics

Abizern
- 146,289
- 39
- 203
- 257

Azeem.Butt
- 5,855
- 1
- 26
- 22
-
3Within that, the closest to a bit blitter equivalent is the CGContextDrawLayerAtPoint function used in the myDrawFlag example code. See: http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_layers/dq_layers.html#//apple_ref/doc/uid/TP30001066-CH219-TPXREF101 – Matt Gallagher Oct 26 '09 at 12:50
-
thanks! I'm pretty sure that doesn't allow you to copy from one image... what is black (and not white) in the other image (it's vector mask). It seems to be very helpful for copying tiles or rects and snippets of images that you create, but not copying existing files that are preloaded as an NSImage in Objective-C/Cocoa... and certainly not copying those images based on its vector mask. Correct me if I am wrong about that, though. – Brian Oct 26 '09 at 16:56
-
You can draw images directly into a CGLayer. You can also mask when you do this. You don't have to use a CGLayer though (it's just fastest because it caches on the graphics card). If you want actual blend modes, you need to use CGContextSetBlendMode and CGContextDrawImage. – Matt Gallagher Oct 26 '09 at 23:09