Author: Tomas Rutkauskas
How to retrieve and display a TJPEGImage from a Paradox blob field
Answer:
Solve 1:
Here's some code to fill a TImage on a form with a JPEGImage from a Paradox blob
field:
1 var2 Stream1: TBlobStream;
3 Photo: TJPEGImage;
4 begin5 Stream1 := TBlobStream.Create(Table1.FieldByName('YourFieldName') as TBlobField,
6 bmRead);
7 Photo := TJPEGImage.create;
8 try9 Photo.LoadFromStream(Stream1);
10 Image1.Picture.Assign(Photo);
11 finally12 Stream1.Free;
13 Photo.Free;
14 end;
15 end;
Solve 2:
Here is an example showing use of the TJPEGImage to display JPEG images in a TImage
component. The JPEG data is stored in a Paradox BLOB field, and this routine is
executed when the record pointer is moved in the table in order to display each new
record's BLOB field contents.
16 procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
17 var18 MS: TMemoryStream;
19 J1: TJPEGImage;
20 begin21 J1 := TJPEGImage.Create;
22 MS := TMemoryStream.Create;
23 try24 TBlobField(DataSet.Fields[1]).SaveToStream(MS);
25 MS.Seek(soFromBeginning, 0);
26 with J1 do27 begin28 PixelFormat := jf24Bit;
29 Scale := jsFullSize;
30 Grayscale := False;
31 Performance := jpBestQuality;
32 ProgressiveDisplay := True;
33 ProgressiveEncoding := True;
34 LoadFromStream(MS);
35 end;
36 Image1.Picture.Graphic.Assign(J1);
37 finally38 J1.Free;
39 MS.Free;
40 end;
41 end;