Quartz 2D Guide 2-graphics contexts

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.