Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sometimes problems with QR Preview and TQRImage

2,005 views
Skip to first unread message

Bernhard Müller

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
I work with Delphi 4 and QuickReport 3.03. In my report I use the component
TQRImage and QR Preview to load a bitmap by the following way:

QRImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Chart.Bmp');
PreviewModal;

Normally it works fine, without problems, but only sometimes if Preview
opens, I get only a black box where the bitmap should be! After that I have
to restart my application before Preview is able to load the bitmap again.

Has somebody any idea where the problem is?

Many thanks and best regards
Bernhard Müller


Colin Acheson

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
There is a problem with QR and/or Delphi with bitmaps and jpg's that
have more than 256 colors. The symptoms are similar to those you
describe. If you create the .bmp's yourself, try saving them as 256
color bitmaps. If you are working with externally created bitmaps
that you have no control over, search the previous postings in this
group. Someone posted a routine that fixes the problem.

Regards,
Colin Acheson

Miha Markic

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
There are problems with more than 256 colors. Use max 256 colors (I had a
similar problem).

Miha

"Bernhard Müller" <albrecht.p...@t-online.de> wrote in message
news:393ca65d@dnews...


> I work with Delphi 4 and QuickReport 3.03. In my report I use the
component
> TQRImage and QR Preview to load a bitmap by the following way:
>
> QRImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Chart.Bmp');
> PreviewModal;
>

> Normally it works fine, without problems, but only sometimes if Preview
> opens, I get only a black box where the bitmap should be! After that I
have
> to restart my application before Preview is able to load the bitmap again.
>
> Has somebody any idea where the problem is?
>

Kurt Dehnel

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Try Preview instead of PreviewModal and see if that makes any difference. I
used to use PreviewModal, but I read somewhere that the internal preparation
is different in each function...

The only other thing I can think of is that there may be an update or help
on the site: www.qusoft.com

Hope this helps,

Kurt Dehnel

Brad White

unread,
Jun 7, 2000, 3:00:00 AM6/7/00
to
QuSoft has stated, and I agree, that there should be no
problem with printing with more than 256 colors.
I for one have had problems with this.

Chris at QuSoft asked me for a small example that
demonstrated this problem so they can research it.
I thought that sounded promising but I haven't been
able to produce one.
If anyone has a small demo please let me know here
and post it to: "borland.public.attachments" with the
same subject.

As for a workaround, sometimes you don't have
control of the color depth of the image.
Use this:

QRImage.Picture.Bitmap.PixelFormat := pf8bit;
QRImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) +
'Chart.Bmp');

If that doesn't work try

MyBitmap := TBitmap.Create;
try
MyBitmap.PixelFormat := pf8bit;
MyBitmap.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Chart.Bmp');
QRImage.Picture.Bitmap.Assign(MyBitmap);

Brad.

Brad White

unread,
Jun 7, 2000, 3:00:00 AM6/7/00
to
I should mention that this workaround is speculation.
Setting the pixelformat works wonders for me, but
I'm not using loadfromfile.
Pixelformat might get reset to match the incoming file.

Brad.


Bernhard Müller

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
Thanks all for your help, I'll try to find the solution with your ideas.

Sorry Brad, I haven't a small demo cause my application runs on a teststand
and it's really difficult to simulate the problem without this background.

One more possibility for the problem should also be the creating of the
bitmap:
DBChart.SaveToBitmapFile('Chart.Bmp');

and another possibility are the ressources of Win NT if the teststand runs
and the printer is printing reports and reports etc.

I'll tell you in the newsgroup if I know the reason for my problem.

Best regards
Bernhard


Brad White <brad_...@my-deja.com> schrieb in im Newsbeitrag:
393e8c19@dnews...

Sylvain Lamothe

unread,
Jun 20, 2000, 3:00:00 AM6/20/00
to

Sorry for all those of you who say that the 256 color mode will fix the
ploblem, but it will not.
It did not for us and we had true color pictures to print anyway.

The problem.
Quick report create a MetaCanvas and then send this metacanvas to the
printer or viewer.
The fact is that QUSoft use the TCanvas.StrechDraw wich use the Windows
StretchBlt API to
draw bitmap to the Metacanvas.
This old API seems to have problems with colors, Specially on Win9x. NT has
no problem with it.

Solution:
Working with DIB (Device Independant Bitmap) eliminates completely the
problem.
The StretchDIBits will transfer all colors to the canvas every time. We
tested it with
over 1000 reports.

To correct the problem you need the source code of Quick report in order to
rewrite
the TQRImage.Print method.

I won't give all the code here but good hints on how to implement it

PS: There were so many bugs in QuickReport that we rewrote most of it.
No More leaks, Stretch that works, Report from a web server to client,
Use from VB and ASP, use in dll etc.


First you need to convert your bitmap to DIB
/////////////////////////////////////////////
file://Sylvain Lamothe///////////////////////////
// ConvertToDiB is a local procedure to TQRImage.Print
Function ConvertToDiB : Boolean;
Var
HeaderSize : DWORD;
ImageSize : DWORD;
LSucess : Boolean;

Begin
Result := False;
Begin
TBitmap(DrawPict.Graphic).IgnorePalette := False;
If TBitmap(DrawPict.Graphic).PixelFormat <> pf24bit Then
TBitmap(DrawPict.Graphic).PixelFormat := pf24bit;
GetDIBSizes(TBitmap(DrawPict.Graphic).Handle, HeaderSize,
ImageSize);
// You need to get memory with GlobalAlloc otherwyse you'll sometimes get
// a black box on a real busy machine. It seem that sometimes Windows move
the memory
// away and the VirtualAlloc from Delphi's Memory Manager can't keep up??.
// If Someone wants to investigate the memory manager you're welcome.

HBitmapHeader := GlobalAlloc(GMEM_MOVEABLE or
GMEM_SHARE,HeaderSize);
BitmapHeader := pBitmapInfo(GlobalLock(HBitmapHeader));

HBitmapImage := GlobalAlloc(GMEM_MOVEABLE or
GMEM_SHARE,ImageSize);
BitmapImage := Pointer(GlobalLock(HBitmapImage));

{********************
GetMem(BitmapHeader, HeaderSize);// Avoid with API
GetMem(BitmapImage, ImageSize);
**********************************}
LSucess := GetDIB(TBitmap(DrawPict.Graphic).Handle,
{TBitmap(DrawPict.Graphic).Palette} 0 ,
BitmapHeader^, BitmapImage^);
Result := LSucess;
End;
End;


StretchDIBits(QRPrinter.Canvas.Handle,
Dest.Left, Dest.Top, // Destination Origin
LWidth2, // Destination Width
LHeight2, // Destination Height
0, 0, // Source Origin
DrawPict.Graphic.Width, // Source Width
DrawPict.Graphic.Height, // Source Height
BitmapImage, // Your DIB
TBitmapInfo(BitmapHeader^),
DIB_RGB_COLORS {DIB_PAL_COLORS},
SRCCOPY);


// Don't forget to free the memory
GlobalUnlock(HBitmapHeader);
GlobalFree(HBitmapHeader);
GlobalUnlock(HBitmapImage);
GlobalFree(HBitmapImage);

Sylvain Lamothe
sylv...@groupid.com
www.groupid.com

0 new messages