Title: How to use webcam in Delphi
Question: Do you need to takes pictures from your Delphi application ?
Answer:
First of all, get the SDK at www.developer.logitec.com
After installation, open delphi and Import ActiveX Control VPortal2 from the list.
Now, create a new form, and put a VideoPortal from the ActiveX panel and a button.
In the uses, add VideoPortal
On the OnShow add:
VideoPortal1.PrepareControl('QCSDK','HKEY_LOCAL_MACHINE\Software\JCS Programmation\QCSDK',0);
VideoPortal1.EnableUIElements(UIELEMENT_STATUSBAR,0,0);
VideoPortal1.ConnectCamera2;
VideoPortal1.EnablePreview := 1;
On the ButtonClick add:
var BMP : TBitmap;
JPG : TJpegImage;
L : String;
begin
F := 'Photos\test.jpg';
VideoPortal1.StampBackgroundColor := clYellow;
VideoPortal1.StampTextColor := clBlack;
VideoPortal1.StampFontName := 'Arial';
VideoPortal1.StampPointSize := 10;
VideoPortal1.StampTransparentBackGround := 0;
L := Format(' %s - %s ',[DateTimeToStr(Now),Num]);
VideoPortal1.PictureToFile(0,24,'Temp.bmp',L);
BMP := TBitmap.Create;
JPG:= TJpegImage.Create;
BMP.LoadFromFile('Temp.bmp');
JPG.CompressionQuality := 85;
JPG.Assign(BMP);
JPG.SaveToFile(F);
BMP.Free;
JPG.Free;
end;
It's all, run the application, you will see the image from the camera, click on the button to get a picture.
Here is a copy a VideoPortal.Pas (constants).
Unit VideoPortal;
Interface
// Copyright (c) 1996-2000 Logitech, Inc. All Rights Reserved
// User Interface Element, codes used with EnableUIElement method
Const UIELEMENT_640x480 = 0;
Const UIELEMENT_320x240 = 1;
Const UIELEMENT_PCSMART = 2;
Const UIELEMENT_STATUSBAR = 3;
Const UIELEMENT_UI = 4;
Const UIELEMENT_CAMERA = 5;
Const UIELEMENT_160x120 = 6;
// Camera status codes, returned by CameraState property
Const CAMERA_OK = 0;
Const CAMERA_UNPLUGGED = 1;
Const CAMERA_INUSE = 2;
Const CAMERA_ERROR = 3;
Const CAMERA_SUSPENDED = 4;
Const CAMERA_DUAL_DETACHED = 5;
Const CAMERA_UNKNOWNSTATUS = 10;
// Movie Recording Modes, used with MovieRecordMode property
Const SEQUENCECAPTURE_FPS_USERSPECIFIED = 1;
Const SEQUENCECAPTURE_FPS_FASTASPOSSIBLE = 2;
Const STEPCAPTURE_MANUALTRIGGERED = 3;
// Movie Creation Flags, used with MovieCreateFlags property
Const MOVIECREATEFLAGS_CREATENEW = 1;
Const MOVIECREATEFLAGS_APPEND = 2;
// Notification Codes
Const NOTIFICATIONMSG_MOTION = 1;
Const NOTIFICATIONMSG_MOVIERECORDERROR = 2;
Const NOTIFICATIONMSG_CAMERADETACHED = 3;
Const NOTIFICATIONMSG_CAMERAREATTACHED = 4;
Const NOTIFICATIONMSG_IMAGESIZECHANGE = 5;
Const NOTIFICATIONMSG_CAMERAPRECHANGE = 6;
Const NOTIFICATIONMSG_CAMERACHANGEFAILED = 7;
Const NOTIFICATIONMSG_POSTCAMERACHANGED = 8;
Const NOTIFICATIONMSG_CAMERBUTTONCLICKED = 9;
Const NOTIFICATIONMSG_VIDEOHOOK = 10;
Const NOTIFICATIONMSG_SETTINGDLGCLOSED = 11;
Const NOTIFICATIONMSG_QUERYPRECAMERAMODIFICATION = 12;
Const NOTIFICATIONMSG_MOVIESIZE = 13;
// Error codes used by NOTIFICATIONMSG_MOVIERECORDERROR notification:
Const WRITEFAILURE_RECORDINGSTOPPED = 0;
Const WRITEFAILURE_RECORDINGSTOPPED_FILECORRUPTANDDELETED = 1;
Const WRITEFAILURE_CAMERA_UNPLUGGED = 2;
Const WRITEFAILURE_CAMERA_SUSPENDED = 3;
// Camera type codes, returned by GetCameraType method
Const CAMERA_UNKNOWN = 0;
Const CAMERA_QUICKCAM_VC = 1;
Const CAMERA_QUICKCAM_QUICKCLIP = 2;
Const CAMERA_QUICKCAM_PRO = 3;
Const CAMERA_QUICKCAM_HOME = 4;
Const CAMERA_QUICKCAM_PRO_B = 5;
Const CAMERA_QUICKCAM_TEKCOM = 6;
Const CAMERA_QUICKCAM_EXPRESS = 7;
Const CAMERA_QUICKCAM_FROG = 8; // MIGHT CHANGE NAME BUT ENUM STAYS THE SAME
Const CAMERA_QUICKCAM_EMERALD = 9; // MIGHT CHANGE NAME BUT ENUM STAYS THE SAME
// Camera-specific property codes used by Set/GetCameraPropertyLong
Const PROPERTY_ORIENTATION = 0;
Const PROPERTY_BRIGHTNESSMODE = 1;
Const PROPERTY_BRIGHTNESS = 2;
Const PROPERTY_CONTRAST = 3;
Const PROPERTY_COLORMODE = 4;
Const PROPERTY_REDGAIN = 5;
Const PROPERTY_BLUEGAIN = 6;
Const PROPERTY_SATURATION = 7;
Const PROPERTY_EXPOSURE = 8;
Const PROPERTY_RESET = 9;
Const PROPERTY_COMPRESSION = 10;
Const PROPERTY_ANTIBLOOM = 11;
Const PROPERTY_LOWLIGHTFILTER = 12;
Const PROPERTY_IMAGEFIELD = 13;
Const PROPERTY_HUE = 14;
Const PROPERTY_PORT_TYPE = 15;
Const PROPERTY_PICTSMART_MODE = 16;
Const PROPERTY_PICTSMART_LIGHT = 17;
Const PROPERTY_PICTSMART_LENS = 18;
Const PROPERTY_MOTION_DETECTION_MODE = 19;
Const PROPERTY_MOTION_SENSITIVITY = 20;
Const PROPERTY_WHITELEVEL = 21;
Const PROPERTY_AUTO_WHITELEVEL = 22;
Const PROPERTY_ANALOGGAIN = 23;
Const PROPERTY_AUTO_ANALOGGAIN = 24;
Const PROPERTY_LOWLIGHTBOOST = 25;
Const PROPERTY_COLORBOOST = 26;
Const PROPERTY_ANTIFLICKER = 27;
Const PROPERTY_OPTIMIZATION_SPEED_QUALITY = 28;
Const PROPERTY_STREAM_HOOK = 29;
Const PROPERTY_LED = 30;
Const ADJUSTMENT_MANUAL = 0;
Const ADJUSTMENT_AUTOMATIC = 1;
Const ORIENTATIONMODE_NORMAL = 0;
Const ORIENTATIONMODE_MIRRORED = 1;
Const ORIENTATIONMODE_FLIPPED = 2;
Const ORIENTATIONMODE_FLIPPED_AND_MIRRORED = 3;
Const COMPRESSION_Q0 = 0;
Const COMPRESSION_Q1 = 1;
Const COMPRESSION_Q2 = 2;
Const ANTIFLICKER_OFF = 0;
Const ANTIFLICKER_50Hz = 1;
Const ANTIFLICKER_60Hz = 2;
Const OPTIMIZE_QUALITY = 0;
Const OPTIMIZE_SPEED = 1;
Const LED_OFF = 0;
Const LED_ON = 1;
Const LED_AUTO = 2;
Const LED_MAX = 3;
Const PICTSMART_LIGHTCORRECTION_NONE = 0;
Const PICTSMART_LIGHTCORRECTION_COOLFLORESCENT = 1;
Const PICTSMART_LIGHTCORRECTION_WARMFLORESCENT = 2;
Const PICTSMART_LIGHTCORRECTION_OUTSIDE = 3;
Const PICTSMART_LIGHTCORRECTION_TUNGSTEN = 4;
Const PICTSMART_LENSCORRECTION_NORMAL = 0;
Const PICTSMART_LENSCORRECTION_WIDEANGLE = 1;
Const PICTSMART_LENSCORRECTION_TELEPHOTO = 2;
Const CAMERADLG_GENERAL = 0;
Const CAMERADLG_ADVANCED = 1;
Implementation
end.