Program code for implementing the camera control using Delphi

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.