欢迎来到天天文库
浏览记录
ID:37916286
大小:42.50 KB
页数:4页
时间:2019-06-02
《Delphi sql 存取图像》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Delphisql存取图像procedureTForm1.Button1Click(Sender:TObject);//插入图片过程var Stream:TMemoryStream;begin try Stream:=TMemoryStream.Create;// 创建内存流 Image1.Picture.Graphic.SaveToStream(Stream); //将图片保存到内存流中 adoquery1.Close; adoquery1.SQL.Clear; adoQuery1.SQL.Add('Insertintotbltemp(Im
2、age)values(:photo)'); //进行插入操作 adoQuery1.Parameters.ParamByName('photo').LoadFromStream(Stream,ftBlob);//读取保存的内存图 adoquery1.ExecSQL; finally Stream.Free; //释放内存流 end;end; procedureTForm1.Button2Click(Sender:TObject);//读取图片过程var Stream:TMemoryStream; Jpg:TjpegImage;begin ADO
3、Query1.Close; ADOQuery1.SQL.Text:='SELECT*FROMtbltemp'; //查询图片 ADOQuery1.Open; ifnotADOQuery1.FieldByName('Image').IsNullthen begin Stream:=TMemoryStream.Create; Jpg:=TjpegImage.Create; TBlobField(ADOQuery1.FieldByName('Image')).SaveToStream(Stream); //显示的转换为BlobField并保存到内存
4、流 Stream.Position:=0; jpg.LoadFromStream(Stream); //加载图片 image2.Picture.Assign(Jpg); end else begin image2.Picture:=nil; end;end;sqlserver2005字段类型为image delphi使用的单元为jpeg,db,dbtables;delphi存储图片代码片段procedureTForm1.btnPostClick(Sender:TObject);var lMemoStream:TMemoryStream; jp
5、g:TJpegImage;begin lMemoStream:=TMemoryStream.Create; jpg:=TJpegimage.Create; jpg.Assign(Img.Picture.Graphic); jpg.SaveToStream(lMemoStream); lMemoStream.Position:=0; TBlobField(dm1.adoqrytea.fieldbyname('image')).LoadFromStream(lMemoStream); dm1.adoqrytea.Post;end;delphi从数据库读取到image
6、中的代码片段procedureTForm3.FormShow(Sender:TObject);var MyJPEG:TJPEGImage; MS:TMemoryStream;begin MyJPEG:=TJPEGImage.Create; MS:=TMemoryStream.Create; ifnotdm1.adostuview.Activethen dm1.adostuview.Open; withdm1.adostuviewdo begin TBlobField(dm1.adostuview.Fields[9]).SaveToStream(MS);
7、 ms.Position:=0; MyJPEG.LoadFromStream(MS); Img.picture.assign(MyJPEG); MyJPEg.free; MS.free; end;end;uses,jpeg,dbshowprocedureTfrmyd.SpeedButton4Click(Sender:TObject);constJPEG_FLAG_BEGIN=$D8FF;JPEG_FLAG_END=$D9FF;varStream:TMemoryStream;Flag1,Flag2:word;Jpg:TjpegImage;begi
8、ndmda
此文档下载收益归作者所有