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;
}
|
|
|