Quartz 2D usage in iOS two: creating a canvas

Source: Internet
Author: User

When using quartz paint in iOS, the first step is to get the canvas (the graphics context) and then do the various things on the canvas. you can see how many context types you can create by looking at the CoreGraphics.h header file first.

#include <CoreGraphics/CGBase.h> #include <CoreGraphics/CGAffineTransform.h> #include <coregraphics/ cgbitmapcontext.h> #include <CoreGraphics/CGColor.h> #include <CoreGraphics/CGColorSpace.h> #include <CoreGraphics/CGContext.h> #include <CoreGraphics/CGDataConsumer.h> #include <coregraphics/ cgdataprovider.h> #include <CoreGraphics/CGError.h> #include <CoreGraphics/CGFont.h> #include < coregraphics/cgfunction.h> #include <CoreGraphics/CGGeometry.h> #include <coregraphics/cggradient.h > #include <CoreGraphics/CGImage.h> #include <CoreGraphics/CGLayer.h> #include <coregraphics/ cgpdfarray.h> #include <CoreGraphics/CGPDFContentStream.h> #include <coregraphics/cgpdfcontext.h># Include <CoreGraphics/CGPDFDictionary.h> #include <CoreGraphics/CGPDFDocument.h> #include < coregraphics/cgpdfobject.h> #include <CoreGraphics/CGPDFOperatorTable.h> #include <coregraphics/ Cgpdfpage.h> #includE <CoreGraphics/CGPDFScanner.h> #include <CoreGraphics/CGPDFStream.h> #include <coregraphics/ cgpdfstring.h> #include <CoreGraphics/CGPath.h> #include <CoreGraphics/CGPattern.h> #include < Coregraphics/cgshading.h>

As you can see, the contexts you can create include:

// Image cgcontextref cgbitmapcontextcreate // Layer (UIView) cgcontextref Cglayergetcontext // PDF Type Cgcontextref cgpdfcontextcreate

Let's look atthe UI Graphics.h this header file, which already provides the methods used by the 3 context-created packages for uikit, in normal cases, using themethods in the UI Graphics, and the canvas has been rotated in coordinates.

 

Uikit_extern cgcontextref uigraphicsgetcurrentcontext (void) cf_returns_not_retained;

Represents a weak reference type, which is used directly without releasing.

Uigraphicsbeginimagecontext (self.bounds.size); Cgcontextref Context=Uigraphicsgetcurrentcontext (); Cgcontextsetrgbfillcolor (Context,1,0,0,1); Cgcontextsetrgbstrokecolor (Context,0,1,0,1); Cgcontextfillrect (Context, CGRectMake (0, -, -, -)); NSString*text=@"text"; Uifont*font=[uifont systemfontofsize: -]; [Text Drawatpoint:cgpointmake (0, $) withAttributes:font.fontDescriptor.fontAttributes]; UIImage*img=[uiimage imagenamed:@"gg.jpg"]; [img Drawinrect:cgrectmake (0, -, -, -)]; Cgimageref cgimg=cgbitmapcontextcreateimage (context); UIImage*resultimg =[UIImage imagewithcgimage:cgimg]; Cgimagerelease (cgimg);

Quartz 2D usage in iOS two: creating a canvas

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.