To load a BLOB field into an image, you need to use TDataSet.CreateBlobStream.
var
Stream: TStream;
JPG: TJpegImage;
begin
JPG := TJpegImage.Create;
try
Stream := Qry.CreateBlobStream(Qry.FieldByName('BLOBVAL'), bmRead);
try
JPG.LoadFromStream(Stream);
finally
BlobStream.Free;
end;
finally
JPG.Free;
end;
end;
To store the image back, you'll need to do the reverse:
var
Stream: TBlobStream;
Jpg: TJpegImage;
begin
Jpg := TJpegImage.Create;
try
Jpg.Assign(Image1.Picture.Graphic);
// Assign other query parameters here
Stream := Qry.CreateBlobStream(Qry.FieldByName('BLOBVAL'), bmWrite);
try
Jpg.SaveToStream(Stream);
Qry.ExecSQL;
finally
Stream.Free;
end;
finally
Jpg.Free;
end;
end;
TDBImage
is only designed to work with bitmaps (when the field is ftGraphic
), so it won't work with JPEG images directly. The easiest thing to do is to load the blob as a JPEG, and assign it to a standard TImage.Picture.Graphic
in an event handler for the dataset (such as it's AfterScroll
event).
qry
variable? – whosrdaddy