gin
picstream.LoadFromFile(opendialog1.filename);
picstream.Position:=0;
adoquery1.edit;
tblobfield(adoquery1.Fields).loadfromstream(picstream);
adoquery1.post;
end;
end;
procedure TForm1.showbuttonClick(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
ghy := TADOBlobstream.Create(Adoquery1pic, bmRead);
try
ghy.Seek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
end;
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
if button in [nbFirst, nbPrior, nbNext, nbLast] then showbutton.Click;
end;
end.
如果数据库中要存储的是BMP文件,则在procedure TForm1.showbuttonClick(Sender: TObject);过程中代码更改如下即可存储显示BMP文件格式的操作。
procedure TForm1.showbuttonClick(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tbitmap;
begin
ghy := TADOBlobstream.Create(Adoquery1pic, bmRead);
try
{ ghy.Seek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);}
Pic:=Tbitmap.Create;
try
Pic.LoadFromStream(ghy);
Image1.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
ghy.Free
end;
end;
到此用DELPHI存取JPEG文件到SQL Server数据库中的具体操作已经叙述完毕。
我的网站:
http://delphijl.99898.com
QQ:123168091