General steps for Quartz 2D drawing

Source: Internet
Author: User
Tags prepare
the steps for customizing UIView using path drawing are as follows1 Call the Uigraphicsgetcurrentcontext () function to get Cgcontextref 2 call Cgcontextbeginpath (cgcontextref __nullable c) function to start defining path 3 Call the following function to draw the sub-path
4 If the path is added complete, call the Cgcontextclosepath () function to close path 5 to set the related properties of the path drawing: line width, fill or path color, etc. 6 call Cgcontextstrokepath (Cgcontextref __nullable c), Cgcontexteofillpath (Cgcontextref __nullable c), Cgcontextfillpath (Cgcontextref __nullable c), CGContextDrawPath ( Cgcontextref __nullable C,
Cgpathdrawingmode mode) to populate the path or draw the path border, the last method in these methods can replace the previous methods, by specifying a different cgpathdrawingmode. drawing pictures in memory
  By extending UIView, overriding the DrawRect: Method for drawing, this method is to draw all the graphics directly on the UIView control, because the DrawRect: method is called every time the control is displayed, which means that all the graphics are redrawn each time the control is displayed. Obviously this performance is very bad, sometimes need to draw pictures in memory, so that can be exported to the phone local, can also be uploaded on the network. Unlike
  drawing directly on UIView, when drawing in memory, developers need to prepare their own drawing environment, and Quartz 2D provides a very agile function:    Uigraphicsbeginimagecontext (cgsize size), which is used to prepare the drawing environment, and when the drawing is complete, you can call the Uigraphicsendimagecontext () function to end the drawing and close the drawing environment.
The steps for drawing in memory are as follows1 Call the Uigraphicsbeginimagecontext (cgsize size) function to prepare the drawing environment 2 call Uigraphicsgetcurrentcontext () function get Cgcontextref 3 call the following function to draw
4 Call the Uigraphicsgetimagefromcurrentimagecontext () function to get the currently drawn picture 5 call the Uigraphicsendimagecontext () function to end the drawing and close the drawing environment

Reference article: "Crazy iOS Handout"

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.