Hi all,
I have been trying to do the following (in OS5):
1. compress and save an offscreen window's bitmap to
an existing record in the storage heap.
2. read the bitmap at a later date.
Part 1 seemed simple. I did something like this:
void Save (WinHandle srcWinH, UInt16 index)
{
BitmapType *destBmP;
WinHandle destWinH;
Err err;
UInt32 headerSize, bitsSize;
MemHandle recH;
MemPtr recP;
recH = DmGetRecord (g_dbRef, index);
if (recH)
{
destBmP = BmpCreate (g_width, g_height, g_depth, NULL, &err);
destWinH = WinCreateBitmapWindow (destBmP, &err);
WinCopyRectangle (srcWinH, destWinH, &g_bounds, 0, 0, winPaint);
BmpCompress (destBmP, BitmapCompressionTypeRLE);
BmpGetSizes (destBmP, &bitsSize, &headerSize);
recH = DmResizeRecord (g_dbRef, index, bitsSize + headerSize);
recP = MemHandleLock (recH);
if (recP)
{
if (BmpSize (destBmP) == headerSize + bitsSize)
{
DmWrite (recP, 0, destBmP, bitsSize + headerSize);
} else
{
// bitmap data not contiguous with header
DmWrite (recP, 0, destBmP, headerSize);
DmWrite (recP, headerSize, BmpGetBits (destBmP), bitsSize);
}
MemHandleUnlock (recH);
}
DmReleaseRecord (g_dbRef, index, true);
}
WinDeleteWindow (destWinH, false);
BmpDelete (destBmP);
}
Part 2 however has me stumped. I did this:
void Load (WinHandle destWinH, UInt16 index)
{
MemHandle recH, bmH;
BitmapType *storedBmP, *bmP;
WinHandle oldWin;
recH = DmQueryRecord (g_dbRef, index);
if (recH)
{
storedBmP = (BitmapType *) MemHandleLock (recH);
bmH = MemHandleNew (MemPtrSize (storedBmP));
bmP = (BitmapType *) MemHandleLock (bmH);
MemMove (bmP, storedBmP, MemPtrSize (storedBmP));
// LINE 1
BmpCompress (bmP, BitmapCompressionTypeNone);
oldWin = WinSetDrawWindow (destWinH);
// LINE 2
WinDrawBitmap (bmP, 0, 0);
WinSetDrawWindow (oldWin);
MemHandleUnlock (recH);
MemHandleUnlock (bmH);
}
}
When run through the Debug Simulator 5.3, I observed that:
- BmpCompress (LINE 1) fails: "invalid bitmapP"
- if I comment out BmpCompress (LINE 1), Sim crashes at
WinDrawBitmap (LINE 2)
Seems obvious that I have an invalid bitmap header. I just
can't figure out how to store it and retrieve it properly.
Any help/advice would be greatly appreciated.
Thanks
Alex
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/