菜单导航

delphi实现保存和读取图片的方法

作者: 精装之家 来源: 精装之家 发布时间: 2019年10月09日 18:11:48

if OpenPictureDialog.Execute then begin img1.Picture.LoadFromFile(OpenPictureDialog.FileName); btnPicture.Text:=OpenPictureDialog.FileName; end;

2.保存图片:

var Stream:TMemoryStream; Stream := TMemoryStream.Create; // 创建内存流 // 将图片保存到内存流中 img1.Picture.Graphic.SaveToStream(Stream); ParamByName('picture').LoadFromStream(Stream,ftBlob); ParamByName('IsSavePicture').Value:='1'; Stream.Free; //用完了马上Free掉

3.读取图片:

var Stream:TMemoryStream; Jpg:TjpegImage; if fieldbyname('IsSavePicture').Value='1' then begin Stream:=TMemoryStream.Create ; Jpg:=TjpegImage.Create ; TBlobField(FieldByName('picture')).SaveToStream(Stream); // 显示的转换为BlobField并保存到内存流 Stream.Position :=0; jpg.LoadFromStream(Stream); // 加载图片 img1.Picture.Assign(Jpg); Stream.Free; Jpg.Free; end else begin img1.Picture :=nil;