function JpegStartsInBlob(PicField:TBlobField):integer;
var
ghy: TADOBlobstream;
buffer:Word;
hx: string;
begin
Result := -1;
ghy := TADOBlobstream.Create(PicField, bmRead);
try
while (Result = -1) and (ghy.Position + 1 < ghy.Size) do
begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'FF' then begin
ghy.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer, 2);
if hx = 'D8' then Result := ghy.Position - 2
else if hx = 'FF' then
ghy.Position := ghy.Position-1;
end; //if
end; //while
finally
ghy.Free
end; //try
end;
procedure TForm1.savebuttonClick(Sender: TObject);
var
picstream:tadoblobstream;
begin
adoquery1.edit;
picstream:=tadoblobstream.Create(tblobfield(adoquery1.fields[1]),bmWrite);
if form1.opendialog1.execute then
begin
picstream.LoadFromFile(opendialog1.filename);
picstream.Position:=0;
adoquery1.edit;
tblobfield(adoquery1.Fields[1]).loadfromstream(picstream);
adoquery1.post;
end;
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
if button in [nbFirst, nbPrior, nbNext, nbLast] then showbutton.Click;
end;
var
ms: TStringStream;
File_Type: string;
begin
if not (Shy_qry.eof and Shy_qry.bof) then
begin
ms := TStringStream.Create('');
OpenPictureDialog1.InitialDir := sm_directory;
if (OpenPictureDialog1.Execute) and (trim(OpenPictureDialog1.filename) <> '') then
begin
File_Type := ExtractFileExt(OpenPictureDialog1.filename);
if UpperCase(File_Type) <> '.JPG' then
begin
OpenPictureDialog1.Filename := BmpToJpg(OpenPictureDialog1.filename);
end;
Image1.picture.loadfromfile(OpenPictureDialog1.filename);
Image1.Picture.Graphic.SaveToStream(ms);
if not (Shy_qry.State in [dsedit, dsinsert]) then
begin
Shy_qry.Edit;
end;
Shy_qry.Fieldbyname('photo_type').AsString := Copy(OpenPictureDialog1.filename, length(OpenPictureDialog1.filename) - 2, 3);
Ms.Position := 0;
(Shy_Qry.Fieldbyname('photo') as Tblobfield).LoadFromStream(ms);
if Shy_Qry.State in [dsedit] then
begin
Shy_qry.Post;
end;
end;
ms.Free;
end
else
begin
Application.MessageBox('请先输入数据再提取照片!', '错误', MB_ICONSTOP + MB_OK);
end;
end;