The complete Delphi photo control code enables the camera to take photos. The tvideocap control is required.
Procedure tfrm1.button2click (Sender: tobject );
VaR
JPEG: tsf-image;
BMP: tbitmap;
Mystm: tmemorystream;
Strfilename, strcard: string;
Begin
Inherited;
Strfilename: = extractfilepath (application. exename );
With dbedit12.datasource. dataset do
Begin
If not videocap1.saveasdib then
Begin
Showmessage ('photo taking failed ');
Abort;
End ;//
BMP: = tbitmap. Create;
Try
BMP. loadfromfile (strfilename + 'capture.bmp ');
Mystm: = tmemorystream. Create;
JPEG: = tsf-image. Create;
Try
JPEG. Assign (BMP );
JPEG. Compress;
JPEG. savetofile (strfilename+'capture.jpg ');
Strfilename: Your strfilename}'capture.jpg ';
JPEG. loadfromfile (strfilename );
JPEG. savetostream (mystm );
Mystm. Position: = 0;
Openqry (query1, 'select count (1) as CNT from tb_photo where card_no = ''' + strcard + '''); // first check whether this card number exists
Openqry (pubqry, 'select * From tb_photo where card_no = ''' + strcard + '''); // open the card number data table
{Openqry is a function used to open a data table.
Openqry (qry1: tquery, ssql: string );
Begin
With qry1 do
Beign
If active then
Close;
SQL. Clear;
SQL. Add (ssql );
Try
Open
Catch
On E: exception do errordialog (E. Message, E. helpcontext );
End; // try
End;
End;
}
With query1 do
Begin
If pubqry. Fields [0]. asinteger> 0 then // first judge whether the image with this card number exists. If so, replace it. Otherwise, insert it.
Edit
Else
Insert;
Fieldbyname ('Card _ no'). asstring: = strcard;
Tblobfield (fieldbyname ('photo'). loadfromstream (mystm );
Post; // unified submission
End; //
Finally
Mystm. Free;
JPEG. Free;
End; // try
Finally
BMP. Free;
End; // try
End; //
End;