.
Home    |    Palm Games   |  Tech SupportTable of Contents   |   About Us    |    Email Us  
Palm Programming
Palm Programming HomepageSourcecodeEmail Us
.
Support
Palm    |    Windows   |    Unix
Subroutines and Snippets
To display a bitmap graphic that we have loaded as a resource (see Concepts and Strategies for more information on resources) we use the Palm API call WinDrawBitmap(). 

This API call is a bit complicated to use, as it takes a pointer to a locked bitmap resource as an argument.  The subroutines below show how we obtain this pointer and lock it.

subroutines that simplify using WinDrawBitmap():

The color coding used:
light bluevariables, constants, and subroutines names chosen by the programmer
light green: 
C defined words, Palm API calls, and all else NOT chosen by the programmer

void
DrawBitmap (int bmpID, int x, int y)
{
   VoidHand
h;
   BitmapPtr
p;
  
 
h = DmGet1Resource('Tbmp', bmpID);
   if (
h != NULL)
   {
    
p = (BitmapPtr ) MemHandleLock(h);
      WinDrawBitmap(
p,x,y);
      DmReleaseResource(
h);
   }
}

examples
(using the subroutines above to display a bitmap graphic)

To display a bitmap we have called bmpLogo (we name our bitmap resources in our IDE) with the upper left corner at col=50 and row=80 (the palms screen is 160 cols by 160 rows)

DrawBitmap(bmpLogo,50,80)
;

tech info


When drawing bitmaps:

1) Drawing bitmaps from resources is slow compared to preloading them in memory, but there is a limited amount of memory into which you may preload graphics.  When its OK to be slow (such as displaying a logo or menu screen) use WinDrawBitmap to conserve memory..

2) Why must we lock the handle?  The handle points to the bitmap resource in memory - and the palm can defragment memory (move the memory around) at any time.  We lock it, forcing the palm to leave it untouched - then we can safely read from it, knowing that it points to the correct place in memory - then we unlock it so that the palm can reuse the memory for other things.

Displaying Bitmaps from a resource