正在做这方面的事情,已成功
下面为例子:(oracle数据库,sql server应该是一样的)
存:
iFlower:TImage;
imBack: TImage;
var
JPeg: TJPegImage;
begin
JPeg := TJPegImage.Create;
if odFile.Execute then
begin
JPeg.LoadFromFile(odFile.FileName);
iFlower.Picture:=nil;
iFlower.Picture.Assign(JPeg);
TBlobField(tFlowerPhoto.FieldbyName('photo')).LoadFromFile(odFile.FileName);
end;
// tFlowerPhoto.Post;
JPeg.Free;
end;
取:
var
SQLstr:String;
JPeg: TJPegImage;
MS: TMemoryStream;
begin
JPeg := TJPegImage.Create;
MS:=TMemoryStream.create;
with qSql do
begin
close;
sql.Clear;
SQLstr:='select photo from table_jpg where ...';
sql.Add(SQLstr);
open;
first;
TBlobField(qSql.FieldbyName('photo')).SaveToStream(MS);
close;
end;
imBack.Picture:=nil;
MS.Position := 0;
jpeg.LoadFromStream(MS);
imBack.Picture.Assign(jpeg);
Jpeg.free;
Ms.free;
end;