Quartz 2D : Overview

1. What is Quartz2D?

It is a 2 dimensional drawing engine available in iOS and MacOS  which canuse the pawer of  graphics hardware if needed.

You can use it for path based drawing, painting with transparency, shading, drawing shadows, transparency layers, color management, anti-aliased rendering and pdf generation.

It can easily communicate with core image, core video, opengl and quick time libraries.

2. What is this page concept in quartz2D?

It is like a painter’s canvas, the order you draw matters. A page can be a sheet of actual paper(print) or virtual paper(pdf) or image.

3. What is a Graphics context?

It is a opaque data type that encapsulates the information Quartz uses to draw images on anything,

All objects in Quartz are drawn to, or contained by, a graphics context.

You can draw the same image to different device(printer, window, layer, bitmap or pdf ) simply by providing different graphics context to the same sequence of Quartz drawing routines.

4. What is the difference between Bitmap Graphics Context and Pdf graphics context?

Bit map is a rectangular array of pixels and quality is tied to the resolution at which the bitmap is intended to be viewed. It is not the case for Pdf, the resulting image is optimised for the display characteristics of the device.

Pdf files can contain may pages.

5.What are Opaque data types? Example please.

Quartz 2D creates objects from opaque data types that your application operates on to achieve a particular drawing output.

– CGPathRef : Create vector paths to stroke and filter

– CGImageRef : create bitmap images and masks

– CGLayerRef : Used fr repeated drawing like backgrounds and patterns.

– CGPatternRef : Used for repeated drawing.

– CGShadingRef, CGGradientRef : Used for paint gradients.

– CGFunctionRef : Used when creating gradients for shading.

– CGColorRef, CGColorSpaceRef : Used to inform quartz how to interpret colours.

– CGImageSourceRef, CGImageDestinationRef : Which is used to move data into and out of Quartz.

– CGFontRef : To draw text

– CGPDFDictioanryRef, CGPDFObjectRef, CGPDFPageRef, CGPDFStream, CGPDFStringRef, CGPDFArrayRef

– CGPDFScannerRef, CGPDFContenStreamRef.

– CGPSConverterRef : NOt available for iOS

6. What is the meaning of Graphics state in Quartz 2D?

Quartz modifies the results of drawing operations according to the parameters in the current graphics state. (Just like OpenGL)

For example when you call a function to set the fill color, you are modifying a value in the current graphic state.

7.Explain the pushing and popping of graphic states?

The graphic contains a stack of graphic states. When Quartz creates a graphic context, the stack is empty.

When you call CGContextSaveGState function is called, all the state of the graphic context is saved into the stack.

When you call CGContextRestoreGState, the current state is replaced with whatever saved in the stack.

8. Could you please provide few samples of graphics states that can be saved to the stack?

– Current transformation matrix (ctm)

– Clipping area

– Line : Width, Join, Cap, Dash, Miter limit

– Color : Fill and Stroke settings

– Anti aliasing settings

– Transparency

– Color Space : Stroke and Fill settings

– Text : Font, font size, character spacing

– Blend mode

9. What do we have to worry about Quartz 2D coordinate system?

The coordinate system is upside down of what is in UIView. Therefore, we may have to apply a CTM matrix in the beginning before we draw anything in to the context.

However, If I use a UIImage to wrap the CGImage object I create, the UIImage wrapper automatically does these transformations for you.

10. How do we handle memory management when it comes to Quartz?

If we make anything with Functions which has “Create” or “Copy” or if use “CFRetain”, then we have to call their “Release” counter parts. That’s all.

Quartz 2D

Damn, it has been 5 weeks since I last wrote. I was really bored reading OpenGL for a while therefore I stopped and carried away with the WWDC stuff. While I was watching WWDC videos, I thought about having  a player where you can watch videos at high speed. Therefore I started to write a player app.

It is coming along very well. However, I have to come to a state where I need to write a custom control set which should be written in core graphics. But, I have zero knowledge in CoreGraphics. Therefore the new course begins now.

I want to log whatever I study, therefore I don’t forget everything I learnt after few months.

If we divide the whole document in to different sections, Overview is about 25 pages, Paths section is 24 pages, colors and color space section is about 9 pages, transforms is 9 pages, patterns section is 15 pages, shadows is 2 pages,Gradient is about 23 pages, transparency layers is about 2 pages, data management is exactly 4 pages, bit maps and image masks section is 30 pages, core graphics layer drawing is about 6 pages, pdf related code is 17 pages, and remaining 9 pages is  about text.

So, Overview, Paths and Bitmap sections are the huge chunks to swallow.

I am hyped. Let see how many pages I can finish by today.