I am converting an app to OS5 and the way bitmaps are handled in OS5 are
different than in previous versions. Specifically, bitmap data may not be
in contiguous memory like in previous versions. The actual bitmap data may
reside at a different memory location than say the header.
I got it working but it is somewhat unstable. I suspect I am not properly
handling the retrieval of the user-written signature window and properly
handling the re-assembling the data into a contiguous memory block so that
it can be processed normally.
The code snippet below retrieves a signature from a form gadget and returns
a pointer to the newly assembled bitmap data which is eventually written to
a database.
Can someone please proofread the way I am handling the assembly and provide
me some input? Everything else in the app works in terms of retrieving
bitmap data from the database and displaying it. But this function seems to
be giving me a headache.
I'm new to the way OS5 treats bitmaps and hopefully a master of this forum
can expand my horizon on this!
Thanks in advance!
Eddie
----------------------------
Given the following code snippet:
static BitmapPtr BuddyGetSignatureBitmap(RectangleType* boundsP)
{
WinHandle signatureWinH;
BitmapPtr signatureP;
UInt16 err;
UInt32 bitmapSize = 0;
Char *bitmapP = NULL;
UInt16 headerSize;
ColorTableType *colorTableP;
UInt16 colorTableSize;
UInt16 bitmapBitsSize;
Char *bitmapBitsP;
// Create offscreen window to copy the bits surrounded by gadget into.
signatureWinH = WinCreateOffscreenWindow(boundsP->extent.x,
boundsP->extent.y,
screenFormat, &err);
if (!err)
{
// Copy gadget screen rectangle into the new window.
WinCopyRectangle(NULL, signatureWinH, boundsP, 0, 0, winPaint);
signatureP = WinGetBitmap(signatureWinH);
bitmapSize = BmpSize(signatureP);
bitmapP = (char*)MemPtrNew(bitmapSize);
if (bitmapP)
{
MemSet(bitmapP, bitmapSize, 0);
colorTableSize = BmpColortableSize(signatureP);
colorTableP = BmpGetColortable(signatureP);
bitmapBitsSize = BmpBitsSize(signatureP);
bitmapBitsP = BmpGetBits(signatureP);
headerSize = bitmapSize - colorTableSize - bitmapBitsSize;
//MemMove(bitmapP, signatureP, bitmapSize);
MemMove(bitmapP, signatureP, headerSize);
MemMove(bitmapP + headerSize, colorTableP, colorTableSize);
MemMove(bitmapP + headerSize + colorTableSize, bitmapBitsP,
bitmapBitsSize);
}
WinDeleteWindow(signatureWinH, false);
}
return (BitmapPtr)bitmapP;
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/