PowerBuilder – Capture Images from Webcam

Posted on Tuesday, August 31st, 2010 at 8:20 pm in

Here’s some code to capture an image from a webcam in Powerbuilder using EZTWAIN. It worked fine on my Vista Home Premium laptop. I came across it earlier in 2010 but the blog page seems to be gone now. If you know the author, let me know so I can give credit.

The file and excellent information can be found at www.dosadi.com/eztwain1.htm

The readme mentions putting the eztw32.dll file in the application folder rather than system32 which I think is a good idea. You don’t have to register the dll.

Global Variables
long mCapHwnd
Constant LONG WM_CAP_DRIVER_CONNECT = 1034
Constant Long WM_CAP_DRIVER_DISCONNECT = 1035
Constant Long WM_CAP_GRAB_FRAME = 1084
Constant Long WM_CAP_EDIT_COPY = 1054
Constant Long WM_CAP_DLG_VIDEOFORMAT = 1065
Constant Long WM_CAP_DLG_VIDEOSOURCE = 1066
Constant String WM_CLOSE = 'H10'

Global External Functions
FUNCTION long DIB_WriteToBmp(long hdib, string pz) LIBRARY 'EZTW32.DLL' alias for 'DIB_WriteToBmp;Ansi'
FUNCTION long TWAIN_AcquireNative(long hwndApp, uint wPixTypes) LIBRARY 'EZTW32.DLL'
FUNCTION long TWAIN_AcquireToClipboard (long hwndApp, uint wPixTypes)  LIBRARY 'EZTW32.DLL'
FUNCTION long TWAIN_AcquireToFilename (long hwndApp, string pz)  LIBRARY 'EZTW32.DLL' alias for 'TWAIN_AcquireToFilename;Ansi'
FUNCTION long TWAIN_FreeNative(long hdib)  LIBRARY 'EZTW32.DLL'
FUNCTION long TWAIN_SelectImageSource (long hwnd) LIBRARY 'EZTW32.DLL'
FUNCTION long TWAIN_SetSaveFormat(int nFF) LIBRARY 'EZTW32.DLL'

Put a Picture button control (pb_1) and a Command button (cb_1) to capture the image.

In the Clicked event of cb_1 :

long ll_ret
ll_ret = TWAIN_AcquireToFilename(0, "c:\temp\result.bmp")
pb_1.picturename='c:\temp\result.bmp'

This is the extent of my use of this. I’m sure much more can be achieved given enough time.

Top