Posted for posterity and for archival searches.

I was looking for a working solution to get a bitmap Ptr of the screen (both
pre/post 3.5 routines).  After much silence and a few wrong answers (or not
complete/legal/buildable examples), I had placed this on the back burner for
now.  I had completed that part of my application using only 3.5 or better
routines.

The Signature ++ example does NOT build in the current SDK and that's the
reason most folks are scrathing thier heads.

I found buildable source (and source that made sense to me) in the Beamer
sample application.  It is posted here for completeness.

/***********************************************************************
 *
 * FUNCTION:   PrvGetBitmap
 *
 * DESCRIPTION: This routine creates a bitmap copy of the bits in the window
passed
 *                This is for compatability with pre version 3.5 roms as
well as 3.5 roms
 *
 * PARAMETERS:  winH           window handle to create bitmap from
 *                            (output bitmap will have same dimensions as
this window)
 *              sizeP          pointer to the size of the created bitmap
 *              errorP        pointer to any error encountered by this
function
 *
 * RETURNED:    Handle to the new bitmap
 *
 *
 ***********************************************************************/
static BitmapPtr PrvGetBitmap (WinHandle winH, UInt32 *sizeP, Err *errorP)
{
    UInt16         width, height;
    UInt16         rowBytes;
    BitmapPtr    bitmapP;
    UInt8         depth;
    WindowType  *winP;

    *errorP = 0;
    *sizeP = 0;
    
    // can we use the new window functions?
    if (newAPI)
        {
        BitmapPtr winBmpP = WinGetBitmap(WinGetDrawWindow());
        ColorTableType *clrTableP = BmpGetColortable(winBmpP);
        UInt8 depth = winBmpP->pixelSize;
        WinHandle winH;
        
        // we create a bitmap and then make a window to it so that we can
        // create a bitmap whose depth does not match that of the screen
        bitmapP = BmpCreate(drawArea.extent.x, drawArea.extent.y, depth,
clrTableP, errorP);
        if (!*errorP)
            {    
            winH = WinCreateBitmapWindow(bitmapP,errorP);
            }
        if (!*errorP)
            {
            // copy draw area into the bitmap
            WinCopyRectangle (WinGetDrawWindow(), winH, &drawArea, 0, 0,
winPaint);
            WinDeleteWindow(winH,false);
    
            // compress the bitmap
            *errorP = BmpCompress(bitmapP,BitmapCompressionTypeScanLine);
        
            // get the size of the bitmap
            *sizeP = BmpSize(bitmapP);
            }
        } 
    else
        {
        winP = WinGetWindowHandle(winH);

        width = winP->windowBounds.extent.x;
        height = winP->windowBounds.extent.y;
        
        depth = 1; // assume one pixel depth
            
        if ((width == 0) || (height == 0))
        {    *errorP = memErrNotEnoughSpace;
            return NULL;
        }
        // Create a display buffer for the window.  Round the line width
        // up to an even word boundary.
        rowBytes = ((((width*depth)+15) >> 4) << 1);
        *sizeP = (rowBytes * height) + sizeof(BitmapType);
        // note that we do NOT output a color map here...
        
        bitmapP = (BitmapPtr) MemPtrNew(*sizeP);
        if (! bitmapP)
        {    *errorP = memErrNotEnoughSpace;
            return NULL;
        }
            
        MemSet(bitmapP,*sizeP,0);  // erase it ...
        
        bitmapP->width = width;
        bitmapP->height = height;
        bitmapP->rowBytes = rowBytes;
        bitmapP->pixelSize = depth;
        bitmapP->version = 1;

        // copy the bitmap contents from the offscreen window
        // The only way to do this on older ROMS is to acesss the obsolete
v20 field.
        MemMove(bitmapP+1,winP->displayAddrV20, rowBytes * height);
        }
    return (bitmapP);
}


-- 
Matt Disher
[EMAIL PROTECTED]


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to