croceldon
croceldon

Reputation: 4595

How to pull jpg from a Blob Field in Delphi and display in a TImage?

I have the following code, but it doesn't display the jpg in the TImage:

  sf := TfrmSplash.Create(nil);
  ms := TMemoryStream.Create;
  try
    bf := TBlobField(dbfuncs.tblBlobs.FieldByName('BBlob'));
    bf.SaveToStream(ms);
    ms.Position := 0;
    sf.imgDisplay.Picture.Graphic.LoadFromStream(ms);
    sf.Show;
    Sleep(2000);
  finally
    ms.Free;
    sf.Free;
  end;

Why doesn't this work? I have jpeg in the uses clause of both forms involved. But nothing is displayed in the image.....

Upvotes: 2

Views: 3993

Answers (2)

NMD
NMD

Reputation: 143

uses
   ... DB;

TBlobField(dbfuncs.tblBlobs.FieldByName('BBlob')).LoadFromFile('file name');
TBlobField(dbfuncs.tblBlobs.FieldByName('BBlob')).LoadFromStream();

Upvotes: 2

robsoft
robsoft

Reputation: 5585

Don't you have to stream it into a TJPEG first, then assign that into the TImage? I don't have code handy here (though can dig it out later) but when I've done this in the past I'm pretty sure I have to do something like

MyJPeg.LoadFromStream

followed by

MyPicture.Graphic.Bitmap.Assign(MyJPeg)...?

Upvotes: 2

Related Questions