Load Picture from Database
Im trying to load a jpeg image stored in a oleobject field in an access database to a TfrxPictureView component. Ive searched the forums, but no-one seems to have an answer.
In my app, I can load an image component using the LoadfromStream method. First, i have to seek to the correct position in the stream before this works correctly.
So im assuming that using the frxpictureview components, i must load from a stream in the onbeforeprint method, but i cant seem to get it to work. Any help is appreciated.
In my app, I can load an image component using the LoadfromStream method. First, i have to seek to the correct position in the stream before this works correctly.
So im assuming that using the frxpictureview components, i must load from a stream in the onbeforeprint method, but i cant seem to get it to work. Any help is appreciated.
Comments
Yes im sure. My current code in my app looks like:
First - function to get the start position in the stream.
function JpegStartsInBlob (PicField:TBlobField):integer;
var
bS : TADOBlobStream;
buffer : Word;
hx : string;
begin
Result := -1;
bS := TADOBlobStream.Create(PicField, bmRead);
try
while (Result = -1) and (bS.Position + 1 < bS.Size) do
begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := bS.Position - 2
else if hx = 'FF' then bS.Position := bS.Position-1;
end; //if
end; //while
finally
bS.Free
end; //try
end;
now the function to read the stream into a picture var.
bS := TADOBlobStream.Create(ImageDataImage, bmRead);
try
bS.Seek(JpegStartsInBlob(ImageDataImage), soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(bS);
finally
Pic.Free;
end;
finally
bS.Free
end;
So - if anyone else comes across this problem, simply select the OLEObject field and assign it to the TFrxPictureView Datafield.