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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s