Graphics in QReport

Graphics in QReport

Post by Don Ston » Wed, 06 Jun 2007 01:50:51


I want to place an image in the detail band of a Quick Report. I am using
Delphi 6 on a Win XP Pro platform. My DBISAM table contains the name of the
image which is stored in a separate folder of which I know it's full path.
I have been told that it is better to put only the name and path in the
DBISAM database and the actual image in a separate folder. However, I must
therefore "load from file" for each record of the detail band with some kind
of event handler (before print, on print, or..).

Can someone please help me get this task working? Or, point me in a
different direction.

Thanks so very much!!
Don
 
 
 

Graphics in QReport

Post by Joe Griffi » Wed, 06 Jun 2007 06:24:26


I did something like this a LONG time ago (the project is now dead
-superseded, but the code is still valid). I did store the images in a
table, but the following should serve as a good starting point.

I was actually putting the picture on a group, rather than the detail
band, but did the following ...

procedure Tqr_RecordCard.QRGroup1BeforePrint(Sender: TQRCustomBand; var
PrintBand: Boolean);
begin
if MainForm.ImagePath = '' then
begin
// No images available
QRAdvImage1.SendToBack;
QRAdvImage1.Enabled := False;
end
else
begin
dmTables.tblImages.open; // Open the table of images
if dmTables.tblImages.locate('Ref_No',
dmQueries.qryRecordRef_No.AsInteger, []) then
begin
// We have an image; load it
QRAdvImage1.BringToFront;
QRAdvImage1.Enabled := True;
LoadPicFromDatabase;
end
else
begin
// No image exists;
QRAdvImage1.SendToBack;
QRAdvImage1.Enabled := False;
end;
dmTables.tblImages.close;
end;
end;

procedure Tqr_RecordCard.LoadPicFromDatabase;
var
FileStream : TFileStream; {a temp file}
FileName : string; {Used to hold a temp file name}
BlobStream : TBlobStream; {the picture Blob}
begin
QRAdvImage1.Picture.Assign(nil);
{Create a blob stream for the blob}
BlobStream := TBlobStream.Create(dmTables.tblImagesMugShot, bmRead);
if BlobStream.Size = 0 then begin
BlobStream.Free;
Exit;
end;
{if we have a temp file then erase it}
if FileName <> '' then
DeleteFile(FileName);
{Get a temp file name}
FileName :=
GetTemporaryFileName(dmTables.tblImagesPictureType.AsString);
{Create a temp file stream}
FileStream := TFileStream.Create(FileName,
fmCreate or fmOpenWrite);
{Copy the blob to the temp file}
FileStream.CopyFrom(BlobStream, BlobStream.Size);
{Free the streams}
FileStream.Free;
BlobStream.Free;
{Display the image}
QRAdvImage1.Picture.LoadFromFile(FileName);
// Finally clear up by removing the temporary file
DeleteFile(FileName);
end;

The images table (tblImages) has two fields - Ref_No (an integer key)
and MugShot (a Blob holding the image data).
The only, slightly odd thing there is I use (my home-brewed) QRAdvImage
component. It's a autoscaling version of QRImage, which resizes the
image to fit a fixed size on the report, maintaining the aspect ratio.

Looking at the code I've pasted; I think you can throw
"LoadPicFromDatabase" away and just replace it with:

QRAdvImage1.Picture.LoadFromFile(FileName);

where "FileName" is stored in your table.

Hope that's of use.

... Joe
Member of the UK Borland User Group

 
 
 

Graphics in QReport

Post by Don Ston » Thu, 07 Jun 2007 11:26:52

oe--
Thank you very much. I believe that you have me pointed in the right
direction.
Don

"Joe Griffin" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...