I have a company logo stored in a SQL Server table. The logo is read into a
memory stream when the program starts up.
I also read the type of the logo, bitmap, jpg, gif or wmf.
How do I transfer the contents of the memoryStream to a TppImage at
run-time?
Comments
Try something like this:
var
lImageStream: TMemoryStream;
lGraphicClass: TGraphicClass;
lGraphicClass := TBitmap; {or whatever class}
lImageStream.Position := 0;
lGraphic := lGraphicClass.Create;
lGraphic.LoadFromStream(lImageStream);
myTppImage.Picture.Graphic := lGraphic;
lGraphic.Free;
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Here's my code:
type
TJCBLOBObject = class (TObject)
ID : integer;
TypeID : smallint;
BLOB : TMemoryStream;
Comment : string;
end;
function loadBlobStreamIntoPicture (BLOBObject : TJCBLOBObject;
Picture : TPicture) : integer;
var
graphicClass : TGraphicClass;
gr : TGraphic;
begin
result := 0;
// The it??? constants are my own, itBitmap is 1, itIcon 2, etc.
case BLOBObject.TypeID of
itBitmap : graphicClass := TBitmap;
itIcon : graphicClass := TIcon;
itMetafile : graphicClass := TMetafile;
itJPG : graphicClass := TJPEGImage;
else graphicClass := nil;
end;
if assigned (graphicClass)
then
begin
// BlobObject.BLOB is the TMemoryStream
BLOBObject.BLOB.position := 0;
gr := graphicClass.create;
try
gr.loadFromStream (BLOBObject.BLOB);
Picture.graphic := gr;
result := BLOBObject.TypeID;
finally
gr.free;
end;
end;
end;
The stream has data, as checked by looking at Blob.size.
I call the routine like this:
loadBlobStreamIntoPicture (licenseeSettings.Logo, imgLogo.picture);
imgLogo is a TppImage.
I tried with bitmap and JPG and neither showed up in the report.
Any help is much appreciated.
I had a TppDBImage in for testing and had not changed back to a TppImage.
With the TppImage the code below works fine.