Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > Legacy Documents > Printing >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

Finding the bit depth of a Carbon Printing Manager graphics context



Q: My application calls PMSessionGetGraphicsContext to get a QuickDraw GrafPort to draw into. Once I have the GrafPort, I call SInt16 depth = GetPixDepth( GetPortPixMap( grafPtr ) ); to determine the depth but the resulting depth is always zero. What am I doing wrong?

A: GetPortPixMap is designed to work with a CGrafPtr, not a GrafPtr, and so always returns NULL if you pass it a GrafPtr. GetPixDepth then returns zero because you passed in NULL. However, the graphics context from PMSessionGetGraphicsContext can be a GrafPtr if you are printing in black and white. If your application needs to find out the depth of the graphics context, you should use the code shown in listing 1.

 Listing 1. Calculating a GrafPort's bit depth.



    SInt16 depth;
    PixMapHandle pmH = GetPortPixMap( grafPtr );
    if ( pmH != NULL ) {
    
            /* process as a CGrafPtr */
        depth = GetPixDepth( pmH );
        
    } else {
    
            /* process as a GrafPtr */
        depth = 1;
        
    }

[Nov 08 2000]