The Quartz context in Objective-C

Creating QR in Objective-C The Quartz context

The Quartz context
QR Maker In Objective-C
Using Barcode generator for iPhone Control to generate, create QR Code ISO/IEC18004 image in iPhone applications.
www.OnBarcode.com
Creating UPC Code In Objective-C
Using Barcode printer for iPhone Control to generate, create UPC-A Supplement 5 image in iPhone applications.
www.OnBarcode.com
Table 19.1 lists these context-related functions, including both the standard UI context functions and the older Core Graphics function that you re most likely to use for PDFs.
Code 128 Code Set B Creation In Objective-C
Using Barcode generation for iPhone Control to generate, create Code-128 image in iPhone applications.
www.OnBarcode.com
DataMatrix Maker In Objective-C
Using Barcode generation for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
Table 19.1 Methods for graphical context creation Function Arguments (none) Summary Returns current context, which is usually the context of the current UIKit object, but could also be a context that you created by hand Creates a bitmap context Pops a bitmap context off the stack Returns a bitmap as a UIImage *; used with a bitmap context only Creates a PDF context
Make Barcode In Objective-C
Using Barcode creator for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Create QR Code ISO/IEC18004 In Objective-C
Using Barcode creator for iPhone Control to generate, create QR Code ISO/IEC18004 image in iPhone applications.
www.OnBarcode.com
UIGraphicsGetCurrentContext
Make EAN / UCC - 13 In Objective-C
Using Barcode creator for iPhone Control to generate, create European Article Number 13 image in iPhone applications.
www.OnBarcode.com
UPC - E1 Creator In Objective-C
Using Barcode encoder for iPhone Control to generate, create UPC-E Supplement 5 image in iPhone applications.
www.OnBarcode.com
UIGraphicsBeginImageContext UIGraphicsEndImageContext UIGraphicsGetImageFromCurrentImageContext
QR Code JIS X 0510 Printer In Visual Studio .NET
Using Barcode generation for Reporting Service Control to generate, create QR-Code image in Reporting Service applications.
www.OnBarcode.com
QR Code JIS X 0510 Creator In None
Using Barcode generation for Word Control to generate, create Quick Response Code image in Word applications.
www.OnBarcode.com
CGSize
Scan Code 39 In .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Barcode Encoder In VS .NET
Using Barcode creator for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
(none)
Read Denso QR Bar Code In VB.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Reading Barcode In VS .NET
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
www.OnBarcode.com
(none)
QR Code Creator In VB.NET
Using Barcode generation for .NET framework Control to generate, create QR Code image in .NET applications.
www.OnBarcode.com
Drawing PDF-417 2d Barcode In None
Using Barcode encoder for Microsoft Word Control to generate, create PDF 417 image in Microsoft Word applications.
www.OnBarcode.com
CGPDFContextCreate
Barcode Generation In None
Using Barcode creator for Microsoft Word Control to generate, create Barcode image in Microsoft Word applications.
www.OnBarcode.com
Creating Barcode In .NET
Using Barcode generator for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
CGDataConsumerRef, CGRect, CGDictionaryRef
ECC200 Generator In Java
Using Barcode drawer for Java Control to generate, create ECC200 image in Java applications.
www.OnBarcode.com
Recognizing PDF-417 2d Barcode In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
We won t be covering PDFs in this book, but we re going to look at how to use each of the UIKit context styles, starting with the UIView.
19.2.1 Drawing to a UIView
In chapter 18, we offered an introductory example of how to write to a UIView graphical context using the drawRect: method. That example was somewhat simplified because the UIKit draw image commands mostly hide the idea of graphical contexts from you. They automatically write to the current context, which inside drawRect: is the context related to the UIView. For most other functions, you ll need to do a bit more work: retrieving the graphical context and passing that context along to any drawing commands that you use. Listing 19.1 shows how to draw a simple abstract face using this technique.
Listing 19.1 A few arcs drawn inside an existing context
- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx);
Graphics: Quartz, Core Animation, and OpenGL
CGContextAddArc(ctx,110,50,30,0,2*M_PI,1); CGContextAddArc(ctx,210,50,30,0,2*M_PI,1); CGContextAddArc(ctx,160,110,15,0,2*M_PI,1); CGContextAddArc(ctx,160,210,25,0,2*M_PI,1); CGContextFillPath(ctx); }
This example is fairly simple. You create a UIView subclass, and then you go to its drawRect: method. Once there, you capture the current context and use it to do whatever Quartz 2D drawing you desire. The function calls won t be familiar to you, but they re calls to draw a bunch of circles; we ll discuss them in the next section. As shown in figure 19.1, the art ends up looking oddly abstract, which shows how Quartz draws continuous paths. You see lines connecting one circle to the next, as if the pencil never comes off the page, a topic we ll talk about more in the next section. Leaving aside those specifics for a moment, this shows one of the two ways that you can use all of the Quartz functions described in this chapter: by painting a UIView. And remember that a UIView can be almost any UIKit object, due to inheritance. Figure 19.1 The iPhone Drawing to a UIView allows for on-screen picture credoes abstract art. ation, but you can also draw pictures without displaying them immediately. That s done with a bitmap.
19.2.2 Drawing to a bitmap
The main reason to create a bitmap rather than draw directly to a view is to use your graphic several times in your program perhaps all at the same time. For example, Apple offers a sample program that draws the periodic table by creating a standard bitmap that s used for all the elements, and then repeating it. You might similarly create billiard balls using bitmaps if you were programming a billiards game. In chapter 17, we could have used Quartz to create the red dots that we used in our gravity and altitude programs as bitmaps, so that we didn t have to separately create them outside of the program. The process of creating a bitmap and turning it into a UIImage is relatively simple. You create a graphical context, draw in that context, save the context to an image, and close the context. Listing 19.2 shows how to create a red dot image like the one you used in earlier programs.
Listing 19.2 A new context created to hold an image
- (void)viewDidLoad { [super viewDidLoad]; UIGraphicsBeginImageContext(CGSizeMake(20,20));
Creates bitmap context
Drawing paths
CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx); CGContextAddArc(ctx,10,10,10,0,2*M_PI,1); CGContextSetRGBFillColor(ctx, 1, 0, 0, 1); CGContextFillPath(ctx);
Copyright © OnBarcode.com . All rights reserved.