tags:

views:

57

answers:

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

+2  A: 

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
Ok - I just tried that, but no go. The jpg still doesn't appear in the TImage....
croceldon
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
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
If I switch to a ShowModal for the form, it shows the bmp file
croceldon
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
A: 

USES ... DB;

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

NMD