试试这个:
导入:
if opendialog1.Execute then
begin
with table1 do begin
open;
insert;
MyFile:=Tfilestream.create(opendialog1.FileName,fmopenread);
Stream := TBlobStream.Create(FieldByName('graphic') as TBlobField, bmWrite);
//graphic为字段名
MemSize := MyFile.Size;
Buffer := AllocMem(MemSize);
try
Stream.Seek(0, soFromBeginning);
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
post;
当然也可以用
DBimage.Picture.LoadFromFile('tmp.bmp');
输出:
var
astream:tblobstream;
fstream:tmemorystream;
begin
if savedialog1.Execute then
begin
fstream:=tmemorystream.Create;
astream:=tblobstream.Create(table1.fieldbyname('graphic') as tblobfield,bmread);
try
fstream.SetSize(astream.Size);
fstream.LoadFromStream(astream);
fstream.SaveToFile(savedialog1.FileName)
finally
astream.Free;
fstream.Free;
end;