資源描述:
《Delphi sql 存取圖像》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Delphisql存取圖像procedureTForm1.Button1Click(Sender:TObject);//插入圖片過(guò)程var?Stream:TMemoryStream;begin?try???Stream:=TMemoryStream.Create;//?創(chuàng)建內(nèi)存流???Image1.Picture.Graphic.SaveToStream(Stream);??//將圖片保存到內(nèi)存流中???adoquery1.Close;???adoquery1.SQL.Clear;???adoQuery1.SQL.Add('Insertintotbltemp(Im
2、age)values(:photo)');???//進(jìn)行插入操作???adoQuery1.Parameters.ParamByName('photo').LoadFromStream(Stream,ftBlob);//讀取保存的內(nèi)存圖???adoquery1.ExecSQL;?finally???Stream.Free;????//釋放內(nèi)存流?end;end;?procedureTForm1.Button2Click(Sender:TObject);//讀取圖片過(guò)程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);???//顯示的轉(zhuǎn)換為BlobField并保存到內(nèi)存
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存儲(chǔ)圖片代碼片段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從數(shù)據(jù)庫(kù)讀取到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