Glam Doc Mac OS
Glam Doc Mac OS
To use a keyboard shortcut, press and hold one or more modifier keys and then press the last key of the shortcut. For example, to use Command-C (copy), press and hold the Command key, then the C key, then release both keys. Mac menus and keyboards often use symbols for certain keys, including modifier keys:
On keyboards made for Windows PCs, use the Alt key instead of Option, and the Windows logo key instead of Command.
Download an executable for Mac¶. LAMMPS can be downloaded, built, and configured for OS X on a Mac with Homebrew. (Alternatively, see the install instructions for Download an executable via Conda.)The following LAMMPS packages are unavailable at this time because of additional needs not yet met: GPU, KOKKOS, LATTE, MSCG, MESSAGE, MPIIO POEMS VORONOI. Before you install Acrobat Reader DC on your computer, ensure that your computer meets the minimum system requirements. If you're on macOS Big Sur, read the Big Sur compatibility document to. Kbl supply de mexico sa de cv logica e informacion sa de cv jorge reyes manzano universidad popular autonoma del estado de puebla ac raul vazquez jr gonzalez.
Some keys on some Apple keyboards have special symbols and functions, such as for display brightness , keyboard brightness , Mission Control, and more. If these functions aren't available on your keyboard, you might be able to reproduce some of them by creating your own keyboard shortcuts. To use these keys as F1, F2, F3, or other standard function keys, combine them with the Fn key.
Cut, copy, paste, and other common shortcuts
- Command-X: Cut the selected item and copy it to the Clipboard.
- Command-C: Copy the selected item to the Clipboard. This also works for files in the Finder.
- Command-V: Paste the contents of the Clipboard into the current document or app. This also works for files in the Finder.
- Command-Z: Undo the previous command. You can then press Shift-Command-Z to Redo, reversing the undo command. In some apps, you can undo and redo multiple commands.
- Command-A: Select All items.
- Command-F: Find items in a document or open a Find window.
- Command-G: Find Again: Find the next occurrence of the item previously found. To find the previous occurrence, press Shift-Command-G.
- Command-H: Hide the windows of the front app. To view the front app but hide all other apps, press Option-Command-H.
- Command-M: Minimize the front window to the Dock. To minimize all windows of the front app, press Option-Command-M.
- Command-O: Open the selected item, or open a dialog to select a file to open.
- Command-P: Print the current document.
- Command-S: Save the current document.
- Command-T: Open a new tab.
- Command-W: Close the front window. To close all windows of the app, press Option-Command-W.
- Option-Command-Esc: Force quit an app.
- Command–Space bar: Show or hide the Spotlight search field. To perform a Spotlight search from a Finder window, press Command–Option–Space bar. (If you use multiple input sources to type in different languages, these shortcuts change input sources instead of showing Spotlight. Learn how to change a conflicting keyboard shortcut.)
- Control–Command–Space bar: Show the Character Viewer, from which you can choose emoji and other symbols.
- Control-Command-F: Use the app in full screen, if supported by the app.
- Space bar: Use Quick Look to preview the selected item.
- Command-Tab: Switch to the next most recently used app among your open apps.
- Shift-Command-5: In macOS Mojave or later, take a screenshot or make a screen recording. Or use Shift-Command-3 or Shift-Command-4 for screenshots. Learn more about screenshots.
- Shift-Command-N: Create a new folder in the Finder.
- Command-Comma (,): Open preferences for the front app.
Sleep, log out, and shut down shortcuts
You might need to press and hold some of these shortcuts for slightly longer than other shortcuts. This helps you to avoid using them unintentionally.
- Power button: Press to turn on your Mac or wake it from sleep. Press and hold for 1.5 seconds to put your Mac to sleep.* Continue holding to force your Mac to turn off.
- Option–Command–Power button* or Option–Command–Media Eject : Put your Mac to sleep.
- Control–Shift–Power button* or Control–Shift–Media Eject : Put your displays to sleep.
- Control–Power button* or Control–Media Eject : Display a dialog asking whether you want to restart, sleep, or shut down.
- Control–Command–Power button:* Force your Mac to restart, without prompting to save any open and unsaved documents.
- Control–Command–Media Eject : Quit all apps, then restart your Mac. If any open documents have unsaved changes, you will be asked whether you want to save them.
- Control–Option–Command–Power button* or Control–Option–Command–Media Eject : Quit all apps, then shut down your Mac. If any open documents have unsaved changes, you will be asked whether you want to save them.
- Control-Command-Q: Immediately lock your screen.
- Shift-Command-Q: Log out of your macOS user account. You will be asked to confirm. To log out immediately without confirming, press Option-Shift-Command-Q.
* Does not apply to the Touch ID sensor.
Finder and system shortcuts
- Command-D: Duplicate the selected files.
- Command-E: Eject the selected disk or volume.
- Command-F: Start a Spotlight search in the Finder window.
- Command-I: Show the Get Info window for a selected file.
- Command-R: (1) When an alias is selected in the Finder: show the original file for the selected alias. (2) In some apps, such as Calendar or Safari, refresh or reload the page. (3) In Software Update preferences, check for software updates again.
- Shift-Command-C: Open the Computer window.
- Shift-Command-D: Open the desktop folder.
- Shift-Command-F: Open the Recents window, showing all of the files you viewed or changed recently.
- Shift-Command-G: Open a Go to Folder window.
- Shift-Command-H: Open the Home folder of the current macOS user account.
- Shift-Command-I: Open iCloud Drive.
- Shift-Command-K: Open the Network window.
- Option-Command-L: Open the Downloads folder.
- Shift-Command-N: Create a new folder.
- Shift-Command-O: Open the Documents folder.
- Shift-Command-P: Show or hide the Preview pane in Finder windows.
- Shift-Command-R: Open the AirDrop window.
- Shift-Command-T: Show or hide the tab bar in Finder windows.
- Control-Shift-Command-T: Add selected Finder item to the Dock (OS X Mavericks or later)
- Shift-Command-U: Open the Utilities folder.
- Option-Command-D: Show or hide the Dock.
- Control-Command-T: Add the selected item to the sidebar (OS X Mavericks or later).
- Option-Command-P: Hide or show the path bar in Finder windows.
- Option-Command-S: Hide or show the Sidebar in Finder windows.
- Command–Slash (/): Hide or show the status bar in Finder windows.
- Command-J: Show View Options.
- Command-K: Open the Connect to Server window.
- Control-Command-A: Make an alias of the selected item.
- Command-N: Open a new Finder window.
- Option-Command-N: Create a new Smart Folder.
- Command-T: Show or hide the tab bar when a single tab is open in the current Finder window.
- Option-Command-T: Show or hide the toolbar when a single tab is open in the current Finder window.
- Option-Command-V: Move the files in the Clipboard from their original location to the current location.
- Command-Y: Use Quick Look to preview the selected files.
- Option-Command-Y: View a Quick Look slideshow of the selected files.
- Command-1: View the items in the Finder window as icons.
- Command-2: View the items in a Finder window as a list.
- Command-3: View the items in a Finder window in columns.
- Command-4: View the items in a Finder window in a gallery.
- Command–Left Bracket ([): Go to the previous folder.
- Command–Right Bracket (]): Go to the next folder.
- Command–Up Arrow: Open the folder that contains the current folder.
- Command–Control–Up Arrow: Open the folder that contains the current folder in a new window.
- Command–Down Arrow: Open the selected item.
- Right Arrow: Open the selected folder. This works only when in list view.
- Left Arrow: Close the selected folder. This works only when in list view.
- Command-Delete: Move the selected item to the Trash.
- Shift-Command-Delete: Empty the Trash.
- Option-Shift-Command-Delete: Empty the Trash without confirmation dialog.
- Command–Brightness Down: Turn video mirroring on or off when your Mac is connected to more than one display.
- Option–Brightness Up: Open Displays preferences. This works with either Brightness key.
- Control–Brightness Up or Control–Brightness Down: Change the brightness of your external display, if supported by your display.
- Option–Shift–Brightness Up or Option–Shift–Brightness Down: Adjust the display brightness in smaller steps. Add the Control key to this shortcut to make the adjustment on your external display, if supported by your display.
- Option–Mission Control: Open Mission Control preferences.
- Command–Mission Control: Show the desktop.
- Control–Down Arrow: Show all windows of the front app.
- Option–Volume Up: Open Sound preferences. This works with any of the volume keys.
- Option–Shift–Volume Up or Option–Shift–Volume Down: Adjust the sound volume in smaller steps.
- Option–Keyboard Brightness Up: Open Keyboard preferences. This works with either Keyboard Brightness key.
- Option–Shift–Keyboard Brightness Up or Option–Shift–Keyboard Brightness Down: Adjust the keyboard brightness in smaller steps.
- Option key while double-clicking: Open the item in a separate window, then close the original window.
- Command key while double-clicking: Open a folder in a separate tab or window.
- Command key while dragging to another volume: Move the dragged item to the other volume, instead of copying it.
- Option key while dragging: Copy the dragged item. The pointer changes while you drag the item.
- Option-Command while dragging: Make an alias of the dragged item. The pointer changes while you drag the item.
- Option-click a disclosure triangle: Open all folders within the selected folder. This works only when in list view.
- Command-click a window title: See the folders that contain the current folder.
- Learn how to use Command or Shift to select multiple items in the Finder.
- Click the Go menu in the Finder menu bar to see shortcuts for opening many commonly used folders, such as Applications, Documents, Downloads, Utilities, and iCloud Drive.
Document shortcuts
The behavior of these shortcuts may vary with the app you're using.
- Command-B: Boldface the selected text, or turn boldfacing on or off.
- Command-I: Italicize the selected text, or turn italics on or off.
- Command-K: Add a web link.
- Command-U: Underline the selected text, or turn underlining on or off.
- Command-T: Show or hide the Fonts window.
- Command-D: Select the Desktop folder from within an Open dialog or Save dialog.
- Control-Command-D: Show or hide the definition of the selected word.
- Shift-Command-Colon (:): Display the Spelling and Grammar window.
- Command-Semicolon (;): Find misspelled words in the document.
- Option-Delete: Delete the word to the left of the insertion point.
- Control-H: Delete the character to the left of the insertion point. Or use Delete.
- Control-D: Delete the character to the right of the insertion point. Or use Fn-Delete.
- Fn-Delete: Forward delete on keyboards that don't have a Forward Delete key. Or use Control-D.
- Control-K: Delete the text between the insertion point and the end of the line or paragraph.
- Fn–Up Arrow: Page Up: Scroll up one page.
- Fn–Down Arrow: Page Down: Scroll down one page.
- Fn–Left Arrow: Home: Scroll to the beginning of a document.
- Fn–Right Arrow: End: Scroll to the end of a document.
- Command–Up Arrow: Move the insertion point to the beginning of the document.
- Command–Down Arrow: Move the insertion point to the end of the document.
- Command–Left Arrow: Move the insertion point to the beginning of the current line.
- Command–Right Arrow: Move the insertion point to the end of the current line.
- Option–Left Arrow: Move the insertion point to the beginning of the previous word.
- Option–Right Arrow: Move the insertion point to the end of the next word.
- Shift–Command–Up Arrow: Select the text between the insertion point and the beginning of the document.
- Shift–Command–Down Arrow: Select the text between the insertion point and the end of the document.
- Shift–Command–Left Arrow: Select the text between the insertion point and the beginning of the current line.
- Shift–Command–Right Arrow: Select the text between the insertion point and the end of the current line.
- Shift–Up Arrow: Extend text selection to the nearest character at the same horizontal location on the line above.
- Shift–Down Arrow: Extend text selection to the nearest character at the same horizontal location on the line below.
- Shift–Left Arrow: Extend text selection one character to the left.
- Shift–Right Arrow: Extend text selection one character to the right.
- Option–Shift–Up Arrow: Extend text selection to the beginning of the current paragraph, then to the beginning of the following paragraph if pressed again.
- Option–Shift–Down Arrow: Extend text selection to the end of the current paragraph, then to the end of the following paragraph if pressed again.
- Option–Shift–Left Arrow: Extend text selection to the beginning of the current word, then to the beginning of the following word if pressed again.
- Option–Shift–Right Arrow: Extend text selection to the end of the current word, then to the end of the following word if pressed again.
- Control-A: Move to the beginning of the line or paragraph.
- Control-E: Move to the end of a line or paragraph.
- Control-F: Move one character forward.
- Control-B: Move one character backward.
- Control-L: Center the cursor or selection in the visible area.
- Control-P: Move up one line.
- Control-N: Move down one line.
- Control-O: Insert a new line after the insertion point.
- Control-T: Swap the character behind the insertion point with the character in front of the insertion point.
- Command–Left Curly Bracket ({): Left align.
- Command–Right Curly Bracket (}): Right align.
- Shift–Command–Vertical bar ( ): Center align.
- Option-Command-F: Go to the search field.
- Option-Command-T: Show or hide a toolbar in the app.
- Option-Command-C: Copy Style: Copy the formatting settings of the selected item to the Clipboard.
- Option-Command-V: Paste Style: Apply the copied style to the selected item.
- Option-Shift-Command-V: Paste and Match Style: Apply the style of the surrounding content to the item pasted within that content.
- Option-Command-I: Show or hide the inspector window.
- Shift-Command-P: Page setup: Display a window for selecting document settings.
- Shift-Command-S: Display the Save As dialog, or duplicate the current document.
- Shift–Command–Minus sign (-): Decrease the size of the selected item.
- Shift–Command–Plus sign (+): Increase the size of the selected item. Command–Equal sign (=) performs the same function.
- Shift–Command–Question mark (?): Open the Help menu.
Other shortcuts
For more shortcuts, check the shortcut abbreviations shown in the menus of your apps. Every app can have its own shortcuts, and shortcuts that work in one app might not work in another.
- Apple Music shortcuts: Choose Help > Keyboard shortcuts from the menu bar in the Music app.
- Other shortcuts: Choose Apple menu > System Preferences, click Keyboard, then click Shortcuts.
Learn more
- Create your own shortcuts and resolve conflicts between shortcuts
- Change the behavior of the function keys or modifier keys
A graphics context represents a drawing destination. It contains drawing parameters and all device-specific information that the drawing system needs to perform any subsequent drawing commands. A graphics context defines basic drawing attributes such as the colors to use when drawing, the clipping area, line width and style information, font information, compositing options, and several others.
Mac Os Catalina
You can obtain a graphics context by using Quartz context creation functions or by using higher-level functions provided by one of the Mac OS X frameworks or the UIKit framework in iOS. Quartz provides functions for various flavors of Quartz graphics contexts including bitmap and PDF, which you can use to create custom content.
Glam Doc Mac Os Catalina
This chapter shows you how to create a graphics context for a variety of drawing destinations. A graphics context is represented in your code by the data type CGContextRef
, which is an opaque data type. After you obtain a graphics context, you can use Quartz 2D functions to draw to the context, perform operations (such as translations) on the context, and change graphics state parameters, such as line width and fill color.
Drawing to a View Graphics Context in iOS
To draw to the screen in an iOS application, you set up a UIView
object and implement its drawRect:
method to perform drawing. The view’s drawRect:
method is called when the view is visible onscreen and its contents need updating. Before calling your custom drawRect:
method, the view object automatically configures its drawing environment so that your code can start drawing immediately. As part of this configuration, the UIView
object creates a graphics context (a CGContextRef
opaque type) for the current drawing environment. You obtain this graphics context in your drawRect:
method by calling the UIKit function UIGraphicsGetCurrentContext
.
The default coordinate system used throughout UIKit is different from the coordinate system used by Quartz. In UIKit, the origin is in the upper-left corner, with the positive-y value pointing downward. The UIView
object modifies the CTM of the Quartz graphics context to match the UIKit conventions by translating the origin to the upper left corner of the view and inverting the y-axis by multiplying it by -1
. For more information on modified-coordinate systems and the implications in your own drawing code, see Quartz 2D Coordinate Systems.
UIView
objects are described in detail in View Programming Guide for iOS.
Creating a Window Graphics Context in Mac OS X
When drawing in Mac OS X, you need to create a window graphics context that’s appropriate for the framework you are using. The Quartz 2D API itself provides no functions to obtain a windows graphics context. Instead, you use the Cocoa framework to obtain a context for a window created in Cocoa.
You obtain a Quartz graphics context from within the drawRect:
routine of a Cocoa application using the following line of code:
The method currentContext
returns the NSGraphicsContext
instance of the current thread. The method graphicsPort
returns the low-level, platform-specific graphics context represented by the receiver, which is a Quartz graphics context. (Don’t get confused by the method names; they are historical.) For more information see NSGraphicsContext Class Reference.
After you obtain the graphics context, you can call any of the Quartz 2D drawing functions in your Cocoa application. You can also mix Quartz 2D calls with Cocoa drawing calls. You can see an example of Quartz 2D drawing to a Cocoa view by looking at Figure 2-1. The drawing consists of two overlapping rectangles, an opaque red one and a partially transparent blue one. You’ll learn more about transparency in Color and Color Spaces. The ability to control how much you can “see through” colors is one of the hallmark features of Quartz 2D.
To create the drawing in Figure 2-1, you first create a Cocoa application Xcode project. In Interface Builder, drag a Custom View to the window and subclass it. Then write an implementation for the subclassed view, similar to what Listing 2-1 shows. For this example, the subclassed view is named MyQuartzView
. The drawRect:
method for the view contains all the Quartz drawing code. A detailed explanation for each numbered line of code appears following the listing.
Note: The drawRect:
method of the NSView
class is invoked automatically each time the view needs to be drawn. To find out more about overriding the drawRect:
method, see NSView Class Reference.
Listing 2-1 Drawing to a window graphics context
Here’s what the code does:
Obtains a graphics context for the view.
This is where you insert your drawing code. The four lines of code that follow are examples of using Quartz 2D functions.
Sets a red fill color that’s fully opaque. For information on colors and alpha (which sets opacity), see Color and Color Spaces.
Fills a rectangle whose origin is (
0,0
) and whose width is200
and height is100
. For information on drawing rectangles, see Paths.Sets a blue fill color that’s partially transparent.
Fills a rectangle whose origin is (
0,0
) and whose width is100
and height is200
.
Creating a PDF Graphics Context
When you create a PDF graphics context and draw to that context, Quartz records your drawing as a series of PDF drawing commands written to a file. You supply a location for the PDF output and a default media box—a rectangle that specifies bounds of the page. Figure 2-2 shows the result of drawing to a PDF graphics context and then opening the resulting PDF in Preview.
The Quartz 2D API provides two functions that create a PDF graphics context:
CGPDFContextCreateWithURL
, which you use when you want to specify the location for the PDF output as a Core Foundation URL. Listing 2-2 shows how to use this function to create a PDF graphics context.CGPDFContextCreate
, which you use when you want the PDF output sent to a data consumer. (For more information see Data Management in Quartz 2D.) Listing 2-3 shows how to use this function to create a PDF graphics context.
A detailed explanation for each numbered line of code follows each listing.
iOS Note: A PDF graphics context in iOS uses the default coordinate system provided by Quartz, without applying a transform to match the UIKit coordinate system. If your application plans on sharing drawing code between your PDF graphics context and the graphics context provided by UIView
object, your application should modify the CTM of the PDF graphics context to modify the coordinate system. See Quartz 2D Coordinate Systems.
Listing 2-2 Calling CGPDFContextCreateWithURL
to create a PDF graphics context
Here’s what the code does:
Calls the Core Foundation function to create a CFURL object from the CFString object supplied to the
MyPDFContextCreate
function. You passNULL
as the first parameter to use the default allocator. You also need to specify a path style, which for this example is a POSIX-style pathname.Calls the Quartz 2D function to create a PDF graphics context using the PDF location just created (as a CFURL object) and a rectangle that specifies the bounds of the PDF. The rectangle (
CGRect
) was passed to theMyPDFContextCreate
function and is the default page media bounding box for the PDF.Releases the CFURL object.
Returns the PDF graphics context. The caller must release the graphics context when it is no longer needed.
Listing 2-3 Calling CGPDFContextCreate
to create a PDF graphics context
Here’s what the code does:
Calls the Core Foundation function to create a CFURL object from the CFString object supplied to the
MyPDFContextCreate
function. You passNULL
as the first parameter to use the default allocator. You also need to specify a path style, which for this example is a POSIX-style pathname.Creates a Quartz data consumer object using the CFURL object. If you don’t want to use a CFURL object (for example, you want to place the PDF data in a location that can’t be specified by a CFURL object), you can instead create a data consumer from a set of callback functions that you implement in your application. For more information, see Data Management in Quartz 2D.
Calls the Quartz 2D function to create a PDF graphics context passing as parameters the data consumer and the rectangle (of type
CGRect
) that was passed to theMyPDFContextCreate
function. This rectangle is the default page media bounding box for the PDF.Releases the data consumer.
Releases the CFURL object.
Returns the PDF graphics context. The caller must release the graphics context when it is no longer needed.
Listing 2-4 shows how to call the MyPDFContextCreate
routine and draw to it. A detailed explanation for each numbered line of code appears following the listing.
Listing 2-4 Drawing to a PDF graphics context
Here’s what the code does:
Declares a variable for the rectangle that you use to define the PDF media box.
Sets the origin of the media box to
(0,0)
and the width and height to variables supplied by the application.Calls the function
MyPDFContextCreate
(See Listing 2-3) to obtain a PDF graphics context, supplying a media box and a pathname. The macroCFSTR
converts a string to aCFStringRef
data type.Sets up a dictionary with the page options. In this example, only the media box is specified. You don’t have to pass the same rectangle you used to set up the PDF graphics context. The media box you add here supersedes the rectangle you pass to set up the PDF graphics context.
Signals the start of a page. This function is used for page-oriented graphics, which is what PDF drawing is.
Calls Quartz 2D drawing functions. You replace this and the following four lines of code with the drawing code appropriate for your application.
Signals the end of the PDF page.
Releases the dictionary and the PDF graphics context when they are no longer needed.
Glam Doc Mac Os Download
You can write any content to a PDF that’s appropriate for your application—images, text, path drawing—and you can add links and encryption. For more information see PDF Document Creation, Viewing, and Transforming.
Creating a Bitmap Graphics Context
A bitmap graphics context accepts a pointer to a memory buffer that contains storage space for the bitmap. When you paint into the bitmap graphics context, the buffer is updated. After you release the graphics context, you have a fully updated bitmap in the pixel format you specify.
Note: Bitmap graphics contexts are sometimes used for drawing offscreen. Before you decide to use a bitmap graphics context for this purpose, see Core Graphics Layer Drawing. CGLayer objects (CGLayerRef
) are optimized for offscreen drawing because, whenever possible, Quartz caches layers on the video card.
iOS Note: iOS applications should use the function UIGraphicsBeginImageContextWithOptions
instead of using the low-level Quartz functions described here. If your application creates an offscreen bitmap using Quartz, the coordinate system used by bitmap graphics context is the default Quartz coordinate system. In contrast, if your application creates an image context by calling the function UIGraphicsBeginImageContextWithOptions
, UIKit applies the same transformation to the context’s coordinate system as it does to a UIView
object’s graphics context. This allows your application to use the same drawing code for either without having to worry about different coordinate systems. Although your application can manually adjust the coordinate transformation matrix to achieve the correct results, in practice, there is no performance benefit to doing so.
You use the function CGBitmapContextCreate
to create a bitmap graphics context. This function takes the following parameters:
data
. Supply a pointer to the destination in memory where you want the drawing rendered. The size of this memory block should be at least (bytesPerRow
*height
) bytes.width
. Specify the width, in pixels, of the bitmap.height
. Specify the height, in pixels, of the bitmap.bitsPerComponent
. Specify the number of bits to use for each component of a pixel in memory. For example, for a 32-bit pixel format and an RGB color space, you would specify a value of 8 bits per component. See Supported Pixel Formats.bytesPerRow
. Specify the number of bytes of memory to use per row of the bitmap.Tip: When you create a bitmap graphics context, you’ll get the best performance if you make sure the data and
bytesPerRow
are 16-byte aligned.colorspace
. The color space to use for the bitmap context. You can provide a Gray, RGB, CMYK, or NULL color space when you create a bitmap graphics context. For detailed information on color spaces and color management principles, see Color Management Overview. For information on creating and using color spaces in Quartz, see Color and Color Spaces. For information about supported color spaces, see Color Spaces and Bitmap Layout in the Bitmap Images and Image Masks chapter.bitmapInfo
. Bitmap layout information, expressed as aCGBitmapInfo
constant, that specifies whether the bitmap should contain an alpha component, the relative location of the alpha component (if there is one) in a pixel, whether the alpha component is premultiplied, and whether the color components are integer or floating-point values. For detailed information on what these constants are, when each is used, and Quartz-supported pixel formats for bitmap graphics contexts and images, see Color Spaces and Bitmap Layout in the Bitmap Images and Image Masks chapter.
Listing 2-5 shows how to create a bitmap graphics context. When you draw into the resulting bitmap graphics context, Quartz records your drawing as bitmap data in the specified block of memory. A detailed explanation for each numbered line of code follows the listing.
Listing 2-5 Creating a bitmap graphics context
Here’s what the code does:
Declares a variable to represent the number of bytes per row. Each pixel in the bitmap in this example is represented by 4 bytes; 8 bits each of red, green, blue, and alpha.
Creates a generic RGB color space. You can also create a CMYK color space. See Color and Color Spaces for more information and for a discussion of generic color spaces versus device dependent ones.
Calls the
calloc
function to create and clear a block of memory in which to store the bitmap data. This example creates a 32-bit RGBA bitmap (that is, an array with 32 bits per pixel, each pixel containing 8 bits each of red, green, blue, and alpha information). Each pixel in the bitmap occupies 4 bytes of memory. In Mac OS X 10.6 and iOS 4, this step can be omitted—if you passNULL
as bitmap data, Quartz automatically allocates space for the bitmap.Creates a bitmap graphics context, supplying the bitmap data, the width and height of the bitmap, the number of bits per component, the bytes per row, the color space, and a constant that specifies whether the bitmap should contain an alpha channel and its relative location in a pixel. The constant
kCGImageAlphaPremultipliedLast
indicates that the alpha component is stored in the last byte of each pixel and that the color components have already been multiplied by this alpha value. See The Alpha Value for more information on premultiplied alpha.If the context isn’t created for some reason, frees the memory allocated for the bitmap data.
Releases the color space.
Returns the bitmap graphics context. The caller must release the graphics context when it is no longer needed.
Listing 2-6 shows code that calls MyCreateBitmapContext
to create a bitmap graphics context, uses the bitmap graphics context to create a CGImage
object, then draws the resulting image to a window graphics context. Figure 2-3 shows the image drawn to the window. A detailed explanation for each numbered line of code follows the listing.
Listing 2-6 Drawing to a bitmap graphics context
Here’s what the code does:
Declares a variable to store the origin and dimensions of the bounding box into which Quartz will draw an image created from the bitmap graphics context.
Sets the origin of the bounding box to
(0,0)
and the width and height to variables previously declared, but whose declaration are not shown in this code.Calls the application-supplied function
MyCreateBitmapContext
(see Listing 2-5) to create a bitmap context that is 400 pixels wide and 300 pixels high. You can create a bitmap graphics context using any dimensions that are appropriate for your application.Calls Quartz 2D functions to draw into the bitmap graphics context. You would replace this and the next four lines of code with drawing code appropriate for your application.
Creates a Quartz 2D image (
CGImageRef
) from the bitmap graphics context.Draws the image into the location in the window graphics context that is specified by the bounding box. The bounding box specifies the location and dimensions in user space in which to draw the image.
This example does not show the creation of the window graphics context. See Creating a Window Graphics Context in Mac OS X for information on how to create one.
Gets the bitmap data associated with the bitmap graphics context.
Releases the bitmap graphics context when it is no longer needed.
Free the bitmap data if it exists.
Releases the image when it is no longer needed.
Supported Pixel Formats
Table 2-1 summarizes the pixel formats that are supported for bitmap graphics context, the associated color space (cs
), and the version of Mac OS X in which the format was first available. The pixel format is specified as bits per pixel (bpp) and bits per component (bpc). The table also includes the bitmap information constant associated with that pixel format. See CGImage Reference for details on what each of the bitmap information format constants represent.
CS | Pixel format and bitmap information constant | Availability |
---|---|---|
Null | 8 bpp, 8 bpc, | Mac OS X, iOS |
Gray | 8 bpp, 8 bpc, | Mac OS X, iOS |
Gray | 8 bpp, 8 bpc, | Mac OS X, iOS |
Gray | 16 bpp, 16 bpc, | Mac OS X |
Gray | 32 bpp, 32 bpc, | Mac OS X |
RGB | 16 bpp, 5 bpc, | Mac OS X, iOS |
RGB | 32 bpp, 8 bpc, | Mac OS X, iOS |
RGB | 32 bpp, 8 bpc, | Mac OS X, iOS |
RGB | 32 bpp, 8 bpc, | Mac OS X, iOS |
RGB | 32 bpp, 8 bpc, | Mac OS X, iOS |
RGB | 64 bpp, 16 bpc, | Mac OS X |
RGB | 64 bpp, 16 bpc, | Mac OS X |
RGB | 128 bpp, 32 bpc, | Mac OS X |
RGB | 128 bpp, 32 bpc, | Mac OS X |
CMYK | 32 bpp, 8 bpc, | Mac OS X |
CMYK | 64 bpp, 16 bpc, | Mac OS X |
CMYK | 128 bpp, 32 bpc, | Mac OS X |
Anti-Aliasing
Bitmap graphics contexts support anti-aliasing, which is the process of artificially correcting the jagged (or aliased) edges you sometimes see in bitmap images when text or shapes are drawn. These jagged edges occur when the resolution of the bitmap is significantly lower than the resolution of your eyes. To make objects appear smooth in the bitmap, Quartz uses different colors for the pixels that surround the outline of the shape. By blending the colors in this way, the shape appears smooth. You can see the effect of using anti-aliasing in Figure 2-4. You can turn anti-aliasing off for a particular bitmap graphics context by calling the function CGContextSetShouldAntialias
. The anti-aliasing setting is part of the graphics state.
You can control whether to allow anti-aliasing for a particular graphics context by using the function CGContextSetAllowsAntialiasing
. Pass true
to this function to allow anti-aliasing; false
not to allow it. This setting is not part of the graphics state. Quartz performs anti-aliasing when the context and the graphic state settings are set to true
.
Obtaining a Graphics Context for Printing
Cocoa applications in Mac OS X implement printing through custom NSView
subclasses. A view is told to print by invoking its print:
method. The view then creates a graphics context that targets a printer and calls its drawRect:
method. Your application uses the same drawing code to draw to the printer that it uses to draw to the screen. It can also customize the drawRect:
call to an image to the printer that is different from the one sent to the screen.
For a detailed discussion of printing in Cocoa, see Printing Programming Guide for Mac.
Copyright © 2001, 2017 Apple Inc. All Rights Reserved. Terms of Use Privacy Policy Updated: 2017-03-21
Glam Doc Mac OS