1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
uses ... Graphic, GIFImg, Jpeg,pngimage, DB,
// afficher
procedure DBImage(I : TImage ; D: TDataset; F : TField);
var
m : TStream;
FirstBytes: AnsiString;
begin
if F.IsNull then Exit;
m := D.CreateBlobStream(F,bmRead);
if m <> nil then
begin
try
SetLength(FirstBytes, 8);
m.Read(FirstBytes[1], 8);
if Copy(FirstBytes, 1, 2) = 'BM' then I.Picture.Graphic := TBitmap.Create
else
if FirstBytes = #137'PNG'#13#10#26#10
then I.Picture.Graphic := TPngImage.Create
else
if Copy(FirstBytes, 1, 3) = 'GIF'
then I.Picture.Graphic := TGIFImage.Create
else if Copy(FirstBytes, 1, 2) = #$FF#$D8
then I.Picture.Graphic := TJPEGImage.Create;
try
m.Seek(0,0);
I.Picture.Graphic.LoadFromStream(m);
except
end;
finally
m.Free;
end;
end;
end;
// écrire
procedure Image2DB(I : TImage ; D: TDataset; F : TField);
var
m : TStream;
begin
m := D.CreateBlobStream(F,bmRead);
if m <> nil then
begin
try
if not i.Picture.Graphic.Empty then i.Picture.Graphic.SaveToStream(m);
if not i.Picture.Bitmap.Empty then i.Picture.Bitmap.SaveToStream(m);
TBlobField(F).LoadFromStream(m);
finally
m.Free;
end;
end;
end; |
Partager