注册 登录
编程论坛 Delphi论坛

如何用ADO连接存取和查询。JPG文件

zmh88111zmh 发布于 2007-12-12 22:32, 1438 次点击
比如员工资料系统中员工与相片的联接。请高手帮忙(最好是有简单例子)
谢谢!
1 回复
#2
xiaxia4212007-12-13 11:02
用流的方式保存图片到数据库
1、保存图片
procedure TForm1.Button1Click(Sender: TObject);
var
MyJPEG : TJPEGImage;
MS: TMemoryStream;
begin
MyJPEG := TJPEGImage.Create;
try
  with MyJPEG do
  begin
   Assign(Image.Picture.Graphic);
   MS:=TMemoryStream.create;
   SaveToStream(MS);
   MS.Position:=0;
   Query1.Edit;
   BlobField(Query1.FieldbyName('Image')).LoadFromStream(MS);
   Query1.Post;
  end;
 finally
  MyJPEG.Free;
 end;
end;

2、查看图片
procedure TForm1.Button1Click(Sender: TObject);
var tempstream:TStringStream;
  tempjpeg:TJPEGImage;
begin
  try
    tempstream:=TStringStream.Create('');
    TBlobField(Query1.FieldByName('Image')).SaveToStream(tempstream);
    tempstream.Position:=0;
    tempjpeg:=TJPEGImage.Create;
    tempjpeg.LoadFromStream(tempstream);
    DBImage1.Picture.Bitmap.Assign(tempjpeg);
 finally
    tempstream.Free;
    tempjpeg.Free;
 end;
end;
1