2

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.....

croceldon
  • 4,511
  • 11
  • 57
  • 92
  • See also [saving and loading image with ADO](http://stackoverflow.com/a/11775398/757830) – NGLN Aug 15 '12 at 19:46

2 Answers2

2

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)...?
robsoft
  • 5,525
  • 4
  • 35
  • 47
  • Ok - I just tried that, but no go. The jpg still doesn't appear in the TImage.... – croceldon Oct 21 '10 at 13:50
  • is there anything unusual about the TImage - are you creating it dynamically or is it an on-form component? Just wondering if there's a handle/parent problem. Can you temporarily hack your code to load a *bitmap* from a local file, just to test that the TImage will definitely show a graphic? Sorry if you've already tried/considered that! – robsoft Oct 21 '10 at 14:03
  • rob, you're on to something - it's not displaying a bmp file that I know is good. But I don't know why, it's just a standard TImage component.... – croceldon Oct 21 '10 at 14:11
  • If I switch to a ShowModal for the form, it shows the bmp file – croceldon Oct 21 '10 at 14:14
  • Try a sf.imgDisplay.Refresh just after the show, it might simply be that it's not getting a chance to repaint the window. – robsoft Oct 21 '10 at 14:16
2
uses
   ... DB;

TBlobField(dbfuncs.tblBlobs.FieldByName('BBlob')).LoadFromFile('file name');
TBlobField(dbfuncs.tblBlobs.FieldByName('BBlob')).LoadFromStream();
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
NMD
  • 143
  • 2
  • 6