The example in this article describes the method of saving and reading pictures in Delphi, which is a very practical technique. Share it with everyone for your reference. The specific implementation method is as follows:
First quote jpeg
1. Display pictures:
if OpenPictureDialog.Execute thenbegin img1.Picture.LoadFromFile(OpenPictureDialog.FileName); btnPicture.Text:=OpenPictureDialog.FileName;end;
2. Save the picture:
varStream:TMemoryStream;Stream := TMemoryStream.Create; // Create a memory stream // Save the picture to the memory stream img1.Picture.Graphic.SaveToStream(Stream);ParamByName('picture').LoadFromStream(Stream,ftBlob); ParamByName('IsSavePicture').Value:='1';Stream.Free; //Free immediately after use3. Read the picture:
varStream:TMemoryStream;Jpg:TjpegImage;if fieldbyname('IsSavePicture').Value='1' thenbegin Stream:=TMemoryStream.Create; Jpg:=TjpegImage.Create; TBlobField(FieldByName('picture')).SaveToStream(Stream) ; // The displayed content is converted to BlobField and saved to the memory stream Stream.Position :=0; jpg.LoadFromStream(Stream); // Load the picture img1.Picture.Assign(Jpg); Stream.Free; Jpg.Free;endelsebegin img1.Picture: =nil;I believe that what is described in this article has certain reference value for everyone's Delphi programming.