Hello. I'm having a problem  capturing a bitmap from a gadget.  I took the
GetSignatureBitmap function from the Signature++ app, which creates and
returns a bitmap of whatever has been drawn in a rectangle.  When I run the
app in POSE using a Palm 3 rom (OS 3.0) the app works fine.  When I run it
using a Palm Pilot rom (OS 2.0) POSE gives me an error saying my app "has
just read directly from low memory". I can continue running the program but
the bitmap isn't saved.  If I run the app on a real Palm  Pilot the program
crashes giving me a fatal error: "MemoryMgr.c, Line:3956, Nil Ptr" and
forces me to reset.

I can't figure out why there are these inconsistencies.  Can anyone offer
any help?

Here's the function that's causing the problem.   According to the debugger
the error occurs at the line:    theRowBytes =
theWindowHandle->gDeviceP->rowBytes;


BitmapPtr GetSignatureBitmap(RectangleType* theBoundsPtr )
{
 WinHandle theWindowHandle;
 Word  theError;
 BitmapPtr theBitmapPtr = NULL;
 Word  theRowBytes, theHeight;

 // Create an offscreen window to copy the bits bounded by the gadget into.
 // This will make converting the window into a bitmap a little easier for
us
 // You could just copy the screen bits directly into the bitmap, but that
 // would require more pointer arithmetic and POSE complains when you read
 // directly from the screen.
 theWindowHandle = WinCreateOffscreenWindow( theBoundsPtr->extent.x,
       theBoundsPtr->extent.y, screenFormat, &theError );

 if (!theError)


  // Now, copy the gadgets screen rectangle into the new window.  This will
offset
  // the screen bits to (0, 0) in the offscreen window.
  WinCopyRectangle( NULL, theWindowHandle, theBoundsPtr, 0, 0, scrCopy );

  // Now, this is the tricky part.  There is no API for getting the bits on
the screen
  // into a bitmap, so this code is unsupported and will only work on Palm
OS 2.x, 3.0,
  // 3.1, and 3.2 devices.  This is why we limit this sample to only those
versions in
  // the RomVersionCompatible function.  This code will also only work on a
device with
  // a screen depth of 1.
  // WARNING:  THIS CODE IS NOT SUPPORTED CODE AND MAY NOT WORK ON DEVICES
  // WHOSE OS VERSION IS OTHER THAN 2.X, 3.0, 3.1, OR 3.2

  // Cache a couple of important bits of information
  theRowBytes = theWindowHandle->gDeviceP->rowBytes;
  theHeight = theWindowHandle->gDeviceP->height;

  // Now, allocate our bitmap and set all the important bits of information.
  theBitmapPtr = (BitmapPtr) MemPtrNew( sizeof(BitmapType) +
(theRowBytes*theHeight) );

  if (theBitmapPtr)
  {
   MemSet( theBitmapPtr, sizeof(BitmapType) + (theRowBytes*theHeight), 0 );

   theBitmapPtr->width = theWindowHandle->gDeviceP->width;
   theBitmapPtr->height = theWindowHandle->gDeviceP->height;
   theBitmapPtr->rowBytes = theWindowHandle->gDeviceP->rowBytes;
   theBitmapPtr->pixelSize = theWindowHandle->gDeviceP->pixelSize;
   theBitmapPtr->nextDepthOffset = NULL;

   // CreateOffscreenWindow does not, by default, create a compressed window
   theBitmapPtr->flags.compressed = theWindowHandle->gDeviceP->compressed;

   // All bitmaps are version 1 bitmaps without a color table.
   theBitmapPtr->version = 1;
   theBitmapPtr->flags.hasColorTable = 0;

   // Move the offscreen bits into our bitmap.  The baseAddr field
   // contains the bit array of our bitmap for 1-bit, uncompressed bitmaps.
   MemMove( (Ptr)((ULong)(theBitmapPtr) + sizeof(BitmapType)),
      theWindowHandle->gDeviceP->baseAddr, theRowBytes * theHeight );
  }

  // Delete the window that we created with WinCreateOffscreenWindow
  WinDeleteWindow( theWindowHandle, false );
 }

 // Finally, return our bitmap
 return theBitmapPtr;
}

Thanks in advance
Luca





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to