function JpegStartsInBlob(PicField:TBlobField):integer;
var
bS : TADOBlobStream;
buffer : Word;
hx :
string;
begin
Result := -1;
bS := TADOBlobStream.Create(PicField, bmRead);
try
while (Result = -1)
and (bS.Position + 1 < bS.Size)
do begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer,2);
if hx = '
FF'
then begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer,2);
if hx = '
D8'
then Result := bS.Position - 2
else if hx = '
FF'
then bS.Position := bS.Position-1;
end;
//if
end;
//while
finally
bS.Free
end;
//try
end;
procedure Tad.ADODataSet1AfterScroll(DataSet: TDataSet);
var
bS : TADOBlobStream;
Pic : TJpegImage;
begin
bS := TADOBlobStream.Create(AdoQuery1Bild, bmRead);
try
bS.Seek(JpegStartsInBlob(AdoQuery1Bild), soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(bS);
ADOImage.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
bS.Free
end;
end;
procedure Tad.Button1Click(Sender: TObject);
begin
if openpicturedialog1.Execute
then
begin
AdoImage.Picture.LoadFromFile(openpicturedialog1.FileName);
end;
end;
procedure Tad.Button2Click(Sender: TObject);
var Stream: TMemoryStream;
aBMP: TBitmap;
aJPG: TJPEGImage;
begin
if AdoImage.Picture.Graphic.Empty
then exit;
Stream := TMemoryStream.Create;
try
aBMP := TBitmap.Create;
try
aJPG := TJPEGImage.Create;
try
try
aBMP.Assign(AdoImage.Picture.Graphic);
aJPG.Assign(aBMP);
aJPG.SaveToStream(Stream);
Stream.Position := 0;
with Adoquery1
do
begin
Close;
SQL.Text := '
INSERT INTO Tabelle1(Bild) VALUES(:img)';
AdoQuery1.Parameters.ParamByName('
img').LoadFromStream(Stream,ftGraphic);
ExecSQL;
end;
MessageBox(
Handle,'
Bild wurde gespeichert','
Information',MB_OK
or MB_ICONINFORMATION);
except
MessageBox(
Handle,'
Bild konnte nicht gespeichert werden','
Fehler',MB_OK
or MB_ICONERROR);
end;
finally
aJPG.Free;
end;
finally
aBMP.Free;
end;
finally
Stream.Free;
end;
end;
procedure Tad.Button3Click(Sender: TObject);
begin
adoquery1.append;
end;
procedure Tad.FormCreate(Sender: TObject);
var sDBPath, sCons:
string;
begin
sDBPath := '
Desktop\Datenbank1.mdb';
sCons := '
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + sDBPath + '
;Persist Security Info=False';
AdoQuery1.Active:=True;
end;
procedure Tad.FormDestroy(Sender: TObject);
begin
AdoQuery1.Active:=False;
end;