Dynamic Image Sizes
Hi,
My name is Darren and I am a developer in Qld Australia.
I am looking for a way to resize header images when they are
printed/rendered in a docket report.
Some background to the problem.
Many vendors each with their own image that can be changed regularly.
Path to image is stored in a datafield and is placed in the report using a
DBImage component
Images are of various shapes and sizes, some are short and wide, some are
square and some are tall.
Requirement is that all images are set to the width of the docket report
which is approximately 70mm
Setting the Autosize property on the DBImage works if all the images are
pre-formatted to 70mm but this is not in my control.
Basically if the DBImage component had a MaxWidth property that worked
alongside Autosize this would be ideal.
I have tried playing with the OnPrint and OnGetImage events of the DBImage
but still havent found a solution though I still suspect that this is where
it could be done?
Any ideas are greatly appreciated
thanks
Darren
My name is Darren and I am a developer in Qld Australia.
I am looking for a way to resize header images when they are
printed/rendered in a docket report.
Some background to the problem.
Many vendors each with their own image that can be changed regularly.
Path to image is stored in a datafield and is placed in the report using a
DBImage component
Images are of various shapes and sizes, some are short and wide, some are
square and some are tall.
Requirement is that all images are set to the width of the docket report
which is approximately 70mm
Setting the Autosize property on the DBImage works if all the images are
pre-formatted to 70mm but this is not in my control.
Basically if the DBImage component had a MaxWidth property that worked
alongside Autosize this would be ideal.
I have tried playing with the OnPrint and OnGetImage events of the DBImage
but still havent found a solution though I still suspect that this is where
it could be done?
Any ideas are greatly appreciated
thanks
Darren
This discussion has been closed.
Comments
Try using the OnPrint event to determine if the image dimensions are too
large and adjust its properties accordingly. Something like the
following...
procedure TForm1.ppDBImage1Print(Sender: TObject);
begin
if ppDBImage1.Picture.Graphic.Width > 25 then
begin
ppDBImage1.AutoSize := False;
ppDBImage1.Stretch := True;
ppDBImage1.MaintainAspectRatio := True;
ppDBImage1.spWidth := 25;
end
else
begin
ppDBImage1.AutoSize := True;
ppDBImage1.Stretch := False;
ppDBImage1.MaintainAspectRatio := False;
end;
end;
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
that code looks like it will work nicely but I am using this in the calc tab
of a reportdesigner (RAP)
procedure DBImage1OnPrint;
begin
if DBImage1.Picture.Graphic.Width > 60 then
begin
DBImage1.AutoSize := False;
DBImage1.Stretch := True;
DBImage1.MaintainAspectRatio := True;
DBImage1.spWidth := 60;
end
else
begin
DBImage1.AutoSize := True;
DBImage1.Stretch := False;
DBImage1.MaintainAspectRatio := False;
end;
end;
end;
I cant seem to get past and error of DBImage1.OnPrint Expected '(' or '['
but graphic found.
Going to have a google and a look around as sure its something simple like
syntax
thanks
procedure DBImage1OnPrint;
begin
if DBImage1.Picture.Graphic.Width > 60 then
begin
DBImage1.AutoSize := False;
DBImage1.Stretch := True;
DBImage1.MaintainAspectRatio := True;
DBImage1.spWidth := 60;
end
else
begin
DBImage1.AutoSize := True;
DBImage1.Stretch := False;
DBImage1.MaintainAspectRatio := False;
end;
end;
end;
if ppDBImage1.Picture.Graphic.Width > 25 then
begin
ppDBImage1.AutoSize := False;
ppDBImage1.Stretch := True;
ppDBImage1.MaintainAspectRatio := True;
ppDBImage1.spWidth := 25;
end
else
begin
ppDBImage1.AutoSize := True;
ppDBImage1.Stretch := False;
ppDBImage1.MaintainAspectRatio := False;
end;
end;
I apologize, I did not know you were using RAP. The Graphic property of
the TPicture is not natively supported in RAP.
The TPicture object however contains passthru properties accessing the
contained TGraphic width and height that you can use in RAP.
if DBImage1.Picture.Width < 60 then
...
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
using DBImage1.Picture.Width still creates the same error,
DBImage1.OnPrint Expected '(' or '[' but Picture found.
I have worked around this issue using the code below.
procedure DBImage1OnPrint;
var vLogo: TPicture;
begin
vLogo := TPicture.create;
vLogo.Assign(DBImage1.Picture);
if vLogo.Width > 60 then
begin
DBImage1.AutoSize := False;
DBImage1.Stretch := True;
DBImage1.MaintainAspectRatio := True;
DBImage1.spWidth := 60;
end
else
begin
DBImage1.AutoSize := True;
DBImage1.Stretch := False;
DBImage1.MaintainAspectRatio := False;
end;
end;
FreeandNil(vLogo);
end;
Thanks Darren
Which version of ReportBuilder are you using? DBImage.Picture support
in RAP is included for the latest version.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
thanks