Quartz 2D Learning Guide for IOS app development

Source: Internet
Author: User

IOS developmentApplicationQuartz 2DThe Learning Guide is the content to be introduced in this article.Quartz 2D. In IOS,Quartz 2DLike Core Animation, OpenGL ES, and UIKit, it works on available graphics and Animation technologies.

1. The Page

Quartz 2D uses painter model to go to imageing. In painter model, each continuous Painting Operation applies a paint layer to the output canvas, which is usually called a page. The painting of an object on the page cannot be modified unless more paint is added. It is built by adding a layer of paint. This model allows us to build complex images with some simple paint.

The following figure shows how the painter model works and the order affects the final effect.

2. Graphics Context

A graphics context is an opaque CGContextRef data type. It encapsulates Quartz information and is used to draw images on an output device, such as a PDF file, bitmap, and display window. The information in graphics context includes the drawing parameters and a page related to the drawing device. All Quartz classes are restricted to drawing on graphics context.

We can use a graphics context as a drawing target. When Quartz is used for plotting, all device-related features are restricted to the specific graphics context. In other words, we provide different graphic context to draw the same image on different devices. We do not need to perform any other operations. Quartz has already helped us.

There are several graphics context types

1) bitmap graphics context

It allows us to paint RGB, CMYK, or grayscale on bitmap. Bitmap is a rectangle array of pixels. Each pixel represents a vertex on the image.

2) PDF graphics context

3) window graphics context

4) layer context

3. Quartz 2D opaque Data Type

In addition to graphics contexts, the Quartz 2D API also defines various opaque data types. Because this API is part of the Core Graphics framework, the data types and functions in the API both use the prefix starting with CG.

Quartz 2D creates an object from a non-transparent data type, and then our application uses it to complete special painting and output. The following describes three objects that can be used for plotting.

We can create a PDF page object to rotate and display this PDF page. Apply a rotation operation in graphics context, and then require Quartz 2D to draw the page in graphics context.

We can create a pattern object and then draw a pattern. Form a pattern to define a shape. We can use pattern paint when drawing a graphics context.

We can create a shading object to fill the shading of an area in the axial or radial direction. Use a function to determine the color of each vertex in the shadow and then fill the shadow with it.

Opaque data types that can be used in Quartz 2D:

 
 
  1. CGPathRef,CGImageRef,CGLayerRef,CGPatternRef,CGShadingRef,CGGradientRef,  
  2. CGFunctionRef,CGColorRef,CGColorSpaceRef,CGImageSourceRef, CGImageDestinationRef, CGFontRef,  

PDF files are not listed.

4. Graphics status

Quartz can modify the Drawing operation result by modifying the current graphics state parameter. The current graphics state determines the final drawing result. For example, when we call a function to set fill color, we actually modify the value stored in the current graphics state. There are other common statuses such as line width, current position, and text font size.

Graphics context includes a graphics states stack. When graphz creates a graphics context, the stack is empty. When a graphics state is saved, Quartz pushes a copy of the current graphics state to the stack. When a graphics state is restored, only pop from the stack is used. CGContextSaveGState function and CGContextRestoreGState function are used to push and pop.

Not all elements in the current drawing environment are in graphics state. For example, the current path is not in graphics state. Some graphics state parameters are listed below:



5. Quartz 2D Coordinate System

The Quratz coordinate system is as follows:

Quratz uses current transformation matrixCTM) to complete the ing between user space and device space for the specific coordinate system ). CTM is a matrix of mathematical structures that can effectively describe related equations. Current transformation matrix is a special matrix type that becomes affine transform. It uses the translation, rotation, and scaling operations to calculate the moving, rotate, and resize operations of a coordinate system) maps a coordinate system point to another coordinate system.

CTM has a second purpose. It allows us to draw objects in transform. For example, if we want to plot a box with 45 degrees of rotation, we can first draw a box and then rotate the coordinate system. Quratz uses the coordinate system of rotation to draw it on the output device.

The default Coordinate System of Quratz, for example, the origin is in the lower left corner. However, graphics context and Quartz created by some technologies use different default coordinate systems. Most commonly, the coordinate system is in the upper left corner of the origin. In the following cases, we use this coordinate system:

In IOS, the drawing context returned by UIView.

In IOS, call the drawing context created by the uigraphicsbeginimagecontextwitexceptions function.

6. Memory Management: object ownership

Quratz uses the Core Foundation memory management model to reference the count. When the Core Foundation object is created, the reference count of the Core Foundation object is 1. We can call the retain function to increase the reference count and call the release function to reduce the reference count.

We need to remember the following points:

1) when we create or copy an object, we have it. After using it, we must release it.

2) if we don't get an object from a function that contains the "create" and "copy" words, we can't help but release it.

3) if we do not have ownership of the object, but we want to save it, We Should reatin it and remember release. For example, if we create a CGColorspace object, we use the CGColorSpaceRetain and CGColorSpaceRelease functions to retain and release.

Summary:IOS developmentApplicationQuartz 2DThe content of the Learning Guide is complete. I hope this article will help you!

Related Article

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.