Saving/retreiving images to and from BLOBs ?

From: Lauchlan M (LMackinnon_at_NOSPAMHotmail.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 19:22:18 +1000

Hi

I need to work out how to best save an image from a Delphi TImage.picture
component into a database BLOB field in a database record, and get it out
again.

I'm trying the following:

  // add the jpg BLOB
  ECGImageBlobStream := TMemoryStream.Create;
  TJPEGImage(imgECG.Picture.Graphic).SaveToStream(ECGImageBlobStream);

nxcmdInsertNewData.ParamByName('ECG_Image').LoadFromStream(ImageBLOBStream,
ftBlob);
  ECGImageBlobStream.Free;

  // get it out again
  ECGImageBlobStream := TMemoryStream.Create;

TBlobField(nxqryGetData.FieldByName('ECG_Image')).SaveToStream(ECGImageBlobS
tream);
  TJPEGImage(imgECG.Picture.Graphic).LoadFromStream(ECGImageBlobStream);
//<-- (*)
  ECGImageBlobStream.Free;

Seems to save ok, but it throws an AV on the line (*) when trying to get the
BLOB out of the DB.

Also, this approach is limited to JPG images, and I'd like to do it more
generally regardless of what kind of image file (jpg, gif, bmp etc) is
involved.

Thanks!

Lauchlan M