你看看下面这段代码可能对你有帮助
procedure TForm1.Button1Click(Sender: TObject); //插入圖片過程
var
testStream:TMemoryStream;
begin
try
testStream := TMemoryStream.Create; //創建內存流
Image1.Picture.Graphic.SaveToStream(testStream); //將圖片保存至內存流中
adoquery1.Close;
adoquery1.SQL.Clear;
adoQuery1.SQL.Add('Insert into test (id,photo) values
![Smile (: (:](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)
id,
![Stick Out Tongue :p :p](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png)
hoto)'); //進行插入操作
adoquery1.Parameters.ParamByName('id').Value := '003';
adoQuery1.Parameters.ParamByName('photo').LoadFromStream(testStream,ftBlob); //讀取保存的內存圖
adoquery1.ExecSQL;
finally
testStream.Free; //釋放內存流
end;
end;
procedure TForm1.Button2Click(Sender: TObject); //讀取圖片過程
var
mStream:TMemoryStream;
JpgFile:TjpegImage;
begin
if not ADOQuery1.FieldByName('photo').IsNull then begin ;
mStream:=TMemoryStream.Create ;
JpgFile:=TjpegImage.Create ;
TBlobField(ADOQuery1.FieldByName('photo')).SaveToStream(mStream); //顯示的轉換為BlobFiled並保存至內存流
mStream.Position :=0;
jpgfile.LoadFromStream(MStream);
image2.Picture.Assign(JpgFile);
end
else begin
image2.Picture :=nil;
end;
end;