unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DBCtrls, Grids, DBGrids, Db, ADODB,jpeg, StdCtrls,dbtables;
{一定要USES JPEG单元,使能存储JPG文件格式}
type
TForm1 = class(TForm)
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
Image1: TImage;
savebutton: TButton;
showbutton: TButton;
OpenDialog1: TOpenDialog;
ADOQuery1id: TIntegerField;
ADOQuery1pic: TBlobField;
procedure savebuttonClick(Sender: TObject);
procedure showbuttonClick(Sender: TObject);
procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R DFM}
function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstreamCreate(PicField, bmRead);
try
while (Result = -1) and (ghyPosition + 1 < ghySize) do
begin
ghyReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = ’FF’ then begin
ghyReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = ’D8’ then Result := ghyPosition - 2
else if hx = ’FF’ then
ghyPosition := ghyPosition-1;
end; //if
end; //while
finally
ghyFree
end; //try
end;
procedure TForm1savebuttonClick(Sender: TObject);
var
picstream:tadoblobstream;
begin
adoquery1edit;
picstream:=tadoblobstreamCreate(tblobfield(adoquery1fields[1]),bmWrite);
if form1opendialog1execute then
begin
picstreamLoadFromFile(opendialog1filename);
picstreamPosition:=0;
adoquery1edit;
tblobfield(adoquery1Fields[1])loadfromstream(picstream);
adoquery1post;
end;
end;
procedure TForm1showbuttonClick(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tjpegimage;
begin
ghy := TADOBlobstreamCreate(Adoquery1pic, bmRead);
try
ghySeek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);
Pic:=TJpegImageCreate;
try
PicLoadFromStream(ghy);
Image1PictureGraphic:=Pic;
finally
PicFree;
end;
finally
ghyFree
end;
end;
procedure TForm1DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
if button in [nbFirst, nbPrior, nbNext, nbLast] then showbuttonClick;
end;
end
如果数据库中要存储的是BMP文件,则在procedure TForm1showbuttonClick(Sender: TObject);过程中代码更改如下即可存储显示BMP文件格式的 *** 作。
procedure TForm1showbuttonClick(Sender: TObject);
var
ghy:TADOBlobstream;
pic:tbitmap;
begin
ghy := TADOBlobstreamCreate(Adoquery1pic, bmRead);
try
{ ghySeek(JpegStartsInBlob(Adoquery1pic),soFromBeginning);}
Pic:=TbitmapCreate;
try
PicLoadFromStream(ghy);
Image1PictureGraphic:=Pic;
finally
PicFree;
end;
finally
ghyFree
end;
end;详细步骤:1登陆花生壳官方网站
>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)