graphics contexts represents a drawing destination. It contains drawing parameters and all device-related information, which is required when the drawing system executes the drawing command. Graphics contexts defines basic drawing attributes, such as the color, clipping area, line width, style information, font information, compositing
options, and others.
you can use quartz context to create a function or IOS uikit framework to obtain a graphics context. Quartz provides several styles of quartz graphics contexts, including bitmap and PDF.
the following article describes how to create graphics contexts for various drawing targets. The data type of graphics context in Code is cgcontextref, which is an opaque data type. After obtaining a graphics context, you can use the quratz 2D function to plot the context, perform operations (such as translations) on the context, and change the status parameters of graphics, for example, line width and fill color.
1. Draw on a view graphics context in IOS.
To draw on an iOS app, you should first create a uiview object and then implement its drawrect: Method to draw. When the view is visible or its content needs to be updated, the view drawrect: method will be called. Before calling the custom drawrect: method, the view object automatically configures its painting environment, and the code can be drawn immediately. As part of the configuration, the uiview object first creates a graphics context for the current drawing environment. We can obtain this graphics by calling the uigraphicsgetcurrentcontext. Function of uikit in the drawrect: method.
Context.
The default coordinate system used by uikit is different from that used by quartz. In uikit, the origin is in the upper left corner. The uiview object uses the translating origin and multiplied by-1 on the Y axis to change the quartz graphics context to match the uikit.
2. Create a bitmap graphics context
A bitmap graphics context accepts a pointer pointing to the memory buffer, which contains a bitmap bucket. When we paint on bitmap graphics context, this buffer will be updated. When graphics context is released, we will have a fully updated bitmap in the specified pixel format.
Use the uigraphicsbeginimagecontextwitexceptions function in IOS.