Is it certain that UIGraphicsBeginImageContext use CGBitmapContextCreate to create the graphics context?

792 views Asked by At

Does UIGraphicsBeginImageContext use CGBitmapContextCreate to create a graphics context [update: I can't find it in the documentation], so the graphics context is exactly the same either way? I also tried to step into UIGraphicsBeginImageContext but the debugger won't let me step into it.

1

There are 1 answers

7
borrrden On

In the UIKit Function References page of iOS documentation, the following is written about UIGraphicsBeginImageContext:

Creates a bitmap-based graphics context and makes it the current context.

Emphasis added. Following a link to the CGContextRef page, I find this:

A graphics context contains drawing parameters and all device-specific information needed to render the paint on a page to the destination, whether the destination is a window in an application, a bitmap image, a PDF document, or a printer.

Again, emphasis added. This says that (as of now) there are 4 kinds of Core Graphics contexts, each with their own initializers. The only kind that has to do with bitmaps is a bitmap-based CGContextRef, and there is only one documented way to create them (well, technically it comes in two versions). It is very likely that this function is being used. I believe that UIGraphicsBeginImageContext is merely a convenience method. It just sets up a default set of parameters for CGBitmapContextCreate (it takes a lot of parameters) and pushes the created context onto the graphics stack.