在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.ACCESS数据表名test,字段id字符,字段photo为OLE 2.在DELPHI窗体中添加ADOQuery1,OpenDialog1,Image1,Button1,Button2,Button3 设置Button3的Caption为“Show Image” 代码如下: procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then Image1.Picture.LoadFromFile(OpenDialog1.FileName); end; procedure TForm1.Button2Click(Sender: TObject); var ms:TMemoryStream; begin if Image1.Picture.Graphic <>nil then begin ms:=TMemoryStream.Create ; Image1.Picture.Graphic.SaveToStream(ms); ADOQuery1.Close; ADOQuery1.SQL.Clear ; ADOQuery1.SQL.Add('insert into test(photo) values(:photo)'); ADOQuery1.Parameters.ParamByName('photo').LoadFromStream(ms,ftBlob); ADOQuery1.execsql; Image1.Picture.Graphic:=nil ; end else showmessage('Please choose a image first!'); end; procedure TForm1.Button3Click(Sender: TObject); var ms:TMemoryStream; jpg:TJPEGImage; begin ADOQuery1.Close; ADOQuery1.SQL.Clear ; ADOQuery1.SQL.Add('select * from test'); ADOQuery1.Open; if not ADOQuery1.FieldByName('photo').IsNull then begin ms:=TMemoryStream.Create ; jpg:=TJPEGImage.Create ; TBlobField(ADOQuery1.FieldByName('photo')).SaveToStream(ms); ms.Position :=0; jpg.LoadFromStream(ms); image1.Picture.Assign(jpg); end else image1.Picture.Graphic :=nil; end; ====================================================================================== 一、 原理介绍--流式数据的类型及其应用 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; Table1.Edit; TBlobField(Table1.FieldbyName('Image')).LoadFromStream(MS); Table1.Post; Messagebox(Getactivewindow(), '图像保存完毕!', '保存', MB_OK); End; Finally MyJPEG.Free; End; End; 在这段代码里TStream的子类TMemoryStream利用内存流起到了将BMP格式转化为JPEG格式 procedure TForm1.Button1Click(Sender: TObject); Var MyJPEG : TJPEGImage; MS : TMemoryStream; Begin Try MS := TMemoryStream.Create; TBlobField(Query1.FieldByName('Image')).SaveToStream(MS); MS.Position := 0; MyJPEG := TJPEGImage.Create; MyJPEG.LoadFromStream(MS); DBImage1.Picture.Bitmap.Assign(MyJPEG); //或是Sender.Picture.Assign(MyJPEG); Finally MS.Free; MyJPEG.Free; End; End; 这段代码的主要作用是:首先将查询结果中的JPEG图像格式数据保存到TMemoryStream中去, |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论