Has anyone ever lost a bitmap loaded into QRImage once QuickRep is printed under Win XP ?


2004-02-01 09:13:00 AM
delphi64
I have no problem to print a report which has a few QRImage under Win98.
However, sometimes the QRImage prints all in black or blank under WinXP.
According to someone's post in the newsgroup, this bug has been for years
and he fixed it up in the source code provided by quick report Pro version.
Before I purchase a Pro version, I just want to know if there is a way to
override PrintBitmap procedure(might be a method) without debugging the
source code.
The following are the patched codes:
I changed the PrintBitmap routine to the following and it fixed the problem
on my machine. There's a problem with AllocMem memory being trashed
apparently (credit to whoever worked it out) so use GlobalAlloc.
Regards
AJAY
{ TQRImage }
procedure PrintBitmap(aCanvas : TCanvas; Dest : TRect; Bitmap : TBitmap);
var
Info : PBitmapInfo;
InfoSize : DWORD;
Image : Pointer;
//
// PATCH: MEMORY ALLOCATION PROBLEM
// --------------------------------
//
HInfo:HGLOBAL; //Declare this new var
HImage:HGLOBAL; //Declare this new var
//
// PATCH: END
// ----------
//
{$ifdef ver80}
ImageSize : Longint;
{$else}
ImageSize : DWord;
{$endif}
begin
with Bitmap do
begin
GetDIBSizes(Handle, InfoSize, ImageSize);
//
// PATCH: MEMORY ALLOCATION PROBLEM
// --------------------------------
//
// This is the source of the problem. AllocMem allocates a memory block on
the
// heap but windows sometimes (expecially during slow down) needs to move to
// another area. The pointer is not updated so quick report prints a black
box.
//
// Info := AllocMem(InfoSize);
//
// The GlobalAlloc function allocates memory on the heap(This Win32 API
// doesn't make difference between local and global heap)
// The second line is the most important. We lock the memory allocated so
that
// windows will never move it and our bitmap pointer will always point to
the
// right memory address.
//
HInfo := GlobalAlloc(GMEM_MOVEABLE or GMEM_SHARE,InfoSize);
Info := PBitmapInfo(GlobalLock(HInfo));
//
// PATCH: END
// ----------
//
try
//
// PATCH: MEMORY ALLOCATION PROBLEM
// --------------------------------
//
// Image := AllocMem(ImageSize);
//
HImage := GlobalAlloc(GMEM_MOVEABLE or GMEM_SHARE,ImageSize);
Image := Pointer(GlobalLock(HImage));
//
// PATCH: END
// ----------
//
try
GetDIB(Handle, Palette, Info^, Image^);
if not Monochrome then
SetStretchBltMode(ACanvas.Handle, STRETCH_DELETESCANS);
with Info^.bmiHeader do
StretchDIBits(aCanvas.Handle, Dest.Left, Dest.Top,
Dest.RIght - Dest.Left, Dest.Bottom - Dest.Top,
0, 0, biWidth, biHeight, Image, Info^, DIB_RGB_COLORS,
SRCCOPY);
finally
//
// PATCH: MEMORY ALLOCATION PROBLEM
// --------------------------------
//
// FreeMem(Image, ImageSize);
GlobalUnlock(HImage); // We first unlock the previously
locked memory
GlobalFree(HImage); // and then we free it
//
// PATCH: END
// ----------
//
end;
finally
//
// PATCH: MEMORY ALLOCATION PROBLEM
// --------------------------------
//
// FreeMem(Info, InfoSize);
GlobalUnlock(HInfo); // We first unlock the previously
locked memory
GlobalFree(HInfo); // and then we free it
//
// PATCH: END
// ----------
//
end;
end;
end;
<XXXX@XXXXX.COM>writes
Quote
same problem exist when printing images Delphi6 + FastReport2.5 + HP
printers + W2K/XP ???,

is the bug in Delphi routines, or interfaces to Windows???
image processing code in QuickReport and FR is identical - GetDIBits,
StrechDIBits, ...

Adam Johnston writes:
>Its a bug in Quick Reports PrintBitmap code thats been there for years
and
>they haven't bothered to fix. You will need to buy the Pro update to
get
>the source code then patch manually.
>>I have a problem printing a report with a QRImage. Sometimes the QRImage
>>print all in black. The image have bmp format, and low resolution (is a
>>enterprise logo).

----------------------------------------------------------------------------
----