保存图片到SQL Server数据库中
procedure TForm4.CttMButton1Click(Sender: TObject);var Stream:TMemoryStream;begin try Stream := TMemoryStream.Create; // 创建内存流 Image1.Picture.Graphic.SaveToStream(Stream); // 将图片保存到内存流中 Stream := Stream; //Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);(另一种方法) ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('Insert into BD_Photo values (:GUID,:sPhoto)'); ADOQuery1.Parameters.ParamByName('GUID').Value :='AB007A7A-00C2-4F4C-BB7F-1D746B17F09A'; ADOQuery1.Parameters.ParamByName('sPhoto').LoadFromStream(Stream,ftBlob); // sPhoto属性image //读取保存的内存图 ADOQuery1.ExecSQL; finally Stream.Free; // 释放内存流 end;end;procedure TForm4.CttMButton1Click(Sender: TObject);var Stream:TMemoryStream;begin try Stream := TMemoryStream.Create; // 创建内存流 Image1.Picture.Graphic.SaveToStream(Stream); // 将图片保存到内存流中 //Stream := Stream; Stream.position := 0; //《========== //Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);(另一种方法) ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('Insert into BD_Photo values (:GUID,:sPhoto)'); ADOQuery1.Parameters.ParamByName('GUID').Value :='AB007A7A-00C2-4F4C-BB7F-1D746B17F09A'; ADOQuery1.Parameters.ParamByName('sPhoto').LoadFromStream(Stream,ftBlob); // sPhoto属性image //读取保存的内存图 ADOQuery1.ExecSQL; finally Stream.Free; // 释放内存流 end;end;