BLOBs images and report ppDBImage elements
Hi.
I have a jpg image, being stored and retreived in the database as follows:
// store the Timage.picture .jpg image in the database:
if not assigned(imgECG.Picture.Graphic) then
datamoduleMain.nxcmdInsertNewSessionData.ParamByName('ECG_Image').Clear //
make it a null
else
begin
ECGImageBlobStream := TMemoryStream.Create;
with imgECG.Picture.Graphic as TJPEGImage do
SaveToStream(ECGImageBlobStream);
ECGImageBlobStream.position := 0;
datamoduleMain.nxcmdInsertNewSessionData.ParamByName('ECG_Image').LoadFromSt
ream(ECGImageBlobStream, ftBlob);
ECGImageBlobStream.Free;
end;
// reload the image from the BLOB field:
imgECG.Picture.Assign(nil); // clear the old image
try
if datamodulemain.nxqryGetSessionData.FieldByName('ECG_Image').IsNull
then
imgECG.Picture.Assign(nil) // this is redundant, but just in case . .
.
else
begin
JPGImage := TJPEGImage.Create;
imgECG.Picture.Assign(JPGImage);
JPGImage.free;
ECGImageBlobStream := TMemoryStream.Create;
TBlobField(datamodulemain.nxqryGetSessionData.FieldByName('ECG_Image')).Save
ToStream(ECGImageBlobStream);
ECGImageBlobStream.position := 0;
if ECGImageBlobStream.Size > 0 then
begin
with imgECG.Picture.Graphic as TJPEGImage do
LoadFromStream(ECGImageBlobStream);
end;
end;
finally
ECGImageBlobStream.Free;
end;
Now, I have a report, and want to use a ppDBImage to display the image.
What do I need to do to get the BLOB field in the right format for the
ppDBImage? At the moment in gives me an error 'Cannot generate report.
Invalid image'.
I'm guessing I need to write a handler for the OnGetPicture or OnPrint
event, but any pointers of what I need to do and how I go about doing it are
appreciated!
Thanks!
Lauchlan M
I have a jpg image, being stored and retreived in the database as follows:
// store the Timage.picture .jpg image in the database:
if not assigned(imgECG.Picture.Graphic) then
datamoduleMain.nxcmdInsertNewSessionData.ParamByName('ECG_Image').Clear //
make it a null
else
begin
ECGImageBlobStream := TMemoryStream.Create;
with imgECG.Picture.Graphic as TJPEGImage do
SaveToStream(ECGImageBlobStream);
ECGImageBlobStream.position := 0;
datamoduleMain.nxcmdInsertNewSessionData.ParamByName('ECG_Image').LoadFromSt
ream(ECGImageBlobStream, ftBlob);
ECGImageBlobStream.Free;
end;
// reload the image from the BLOB field:
imgECG.Picture.Assign(nil); // clear the old image
try
if datamodulemain.nxqryGetSessionData.FieldByName('ECG_Image').IsNull
then
imgECG.Picture.Assign(nil) // this is redundant, but just in case . .
.
else
begin
JPGImage := TJPEGImage.Create;
imgECG.Picture.Assign(JPGImage);
JPGImage.free;
ECGImageBlobStream := TMemoryStream.Create;
TBlobField(datamodulemain.nxqryGetSessionData.FieldByName('ECG_Image')).Save
ToStream(ECGImageBlobStream);
ECGImageBlobStream.position := 0;
if ECGImageBlobStream.Size > 0 then
begin
with imgECG.Picture.Graphic as TJPEGImage do
LoadFromStream(ECGImageBlobStream);
end;
end;
finally
ECGImageBlobStream.Free;
end;
Now, I have a report, and want to use a ppDBImage to display the image.
What do I need to do to get the BLOB field in the right format for the
ppDBImage? At the moment in gives me an error 'Cannot generate report.
Invalid image'.
I'm guessing I need to write a handler for the OnGetPicture or OnPrint
event, but any pointers of what I need to do and how I go about doing it are
appreciated!
Thanks!
Lauchlan M
This discussion has been closed.
Comments
If your images are stored in JPEG format in your database (as BLOB fields),
then you should be able to load them into a report using a TppDBImage
without any special code. Two things to check:
1. Be sure you have ppJPEG included in the "uses" clause of your
application.
2. Be sure the TppDBImage.GraphicType is set to "JPEG". This property can
be set at design time in the Delphi Object Inspector or at runtime in code.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
fields),
can
code.
This worked, thanks.
Lauchlan M