1)存储jpg图片
procedure TMainForm.btnYesClick(Sender: TObject);
var
MyJPEG: TJPEGImage;
MS: TMemoryStream;
begin
MyJpeg := TJpegImage.Create;
try
MyJpeg.Assign(image1.Picture.Graphic)
Ms := TMeMoryStream.Create;
MyJpeg.SaveToStream(Ms);
Ms.Position := 0;
adoqrytest.Edit;
adoqrytest['id'] := '1';
TBlobField(adoqrytest.FieldByName('picture')).LoadFromStream(MS);
adoqrytest.Post;
finally
MyJpeg.Free;
Ms.Free;
end;
end;
2)读取jpg图片
procedure TMainForm.FormShow(Sender: TObject);
var
tempStream: TStringStream;
tempJpeg: TJpegImage;
begin
try
tempStream := TStringStream.Create('');
TBlobField(adoqrytest.FieldByName('picture')).SaveToStream(tempStream);
tempstream.position:=0
tempJpeg := TJpegImage.Create;
tempJpeg.LoadFromStream(tempStream);
DBImage1.Picture.Bitmap.Assign(tempJpeg);
finally
tempStream.Free;
tempJpeg.Free;
end;
end;