Hi,
I was trying to access ole image in an access database. I tried both 
DBImage and Image box. Directly accessing BLOB field does not work. 
Using Stream or BLOBStream also did not work. I tried a worked out 
online example. Again I have problem accesssing the image. The DBGrid 
is able to load ok with all the fields populated as it should. The 
picture field is populated as BLOB. Has anyone any useful suggestions 
on how to do it in the simplest way. Here is the snippet of code

procedure TFormADOBLOB.ButtonShowImageClick(Sender: TObject);
  VAR
    Bitmap      : TBitmap;
    MemoryStream: TMemoryStream;
begin
  MemoryStream := TMemoryStream.Create;
  TRY
    DataModuleNorthwind.ADOQueryNorthwindPhoto.SaveToStream
(MemoryStream);
    // Who can explain why 78 bytes should be skipped here?
    MemoryStream.Seek(78, soFromBeginning);
    Bitmap := TBitmap.Create;
    TRY
      Bitmap.LoadFromStream(MemoryStream);
      Image.Picture.Graphic := Bitmap
    FINALLY
      Bitmap.Free
    END
  FINALLY
    MemoryStream.Free
  END
end;

Francisco Leong suggests a slightly different approach:

VAR
  P:  TADOBlobStream;
...
BEGIN
  P := TADOBlobStream.Create(BlobImageField, bmRead);
  P.Seek(78, soFromBeginning);
  TRY
    Bitmap1.LoadFromStream(P);
  FINALLY
    P.Free
  END
END;

Thxs & Rdgs
Anu Rang
http://totallyfreeenergy.freehoxt.com


Reply via email to