保存图片
procedure TForm1.Button1Click(Sender: TObject);
var
TP:tmemorystream;
JPG:Tjpegimage;
begin
if OpenPictureDialog1.Execute then
begin
image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
TP:=tmemorystream.Create;
JPG:=Tjpegimage.Create;
try
JPG.Assign(image1.Picture.Graphic);
JPG.SaveToStream(TP);
TP.Position:=0;
adodataset1.Insert;
TBlobfield(adodataset1.FieldByName('TP')).LoadFromStream(TP);
adodataset1.Post;
finally
TP.Free;
JPG.Free;
end;
end;
end;
--------------------------------------------------------------------------------------------
显示图片
procedure TForm1.ADODataSet1AfterScroll(DataSet: TDataSet);
var
TP:tmemorystream;
JPG:Tjpegimage;
begin
TP:=tmemorystream.Create;
JPG:=tjpegimage.Create;
try
tblobfield(adodataset1.FieldByName('TP')).SaveToStream(TP);
TP.Position:=0;
JPG.LoadFromStream(TP);
image2.Picture.Assign(JPG);
finally
TP.Free;
JPG.Free;
end;
end;
测试通过