twain and video cap

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by marlo.

Is possible with PB use twain an video capture?

south south america
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

Yes you can (VideoCap) as i know.
But it is difficult, coz you have to code your own with API's only.
In VB there is some Source which can been port(not so difficult) to
PureBasic.Search http://www.PlanetSourceCode.com for Author 'Ray Mercer' or Text 'VideoCapture'.
So Twain is also a easy Port of the VideoCapturing it could also been handled.
(If you cannot find the source, i can mail you)



Its a long way to the top if you wanna .....CodeGuru

Edited by - Rings on 06 May 2002 18:08:22
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by marlo.

Thanks Ring,i like image aquisition,video capture, and audio recording.


from the ass of the world
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by marlo.

Here the code of VB i found about Video Capture, can you help to translate to PB

'Constants
Private Const WM_CAP_DRIVER_CONNECT As Long = 1034
Private Const WM_CAP_DRIVER_DISCONNECT As Long = 1035
Private Const WM_CAP_GRAB_FRAME As Long = 1084
Private Const WM_CAP_EDIT_COPY As Long = 1054
Private Const WM_CAP_DLG_VIDEOFORMAT As Long = 1065
Private Const WM_CAP_DLG_VIDEOSOURCE As Long = 1066
Private Const WM_CLOSE = &H10

'Declarations
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "USER32" () As Long

'Variables
Private mCapHwnd As Long
Private mLivePreview As Boolean

'Methods
Private Sub Form_Load()
mCapHwnd = capCreateCaptureWindow("My Own Capture Window", 0, 0, 0, 320, 240, Me.hwnd, 0)
LivePreview = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
LivePreview = False
SendMessage mCapHwnd, WM_CLOSE, 0, 0
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, &HA1, 2, 0&
End Sub

Private Sub Form_Resize()
Static Running As Boolean
If Running = True Then
Exit Sub
End If
Running = True
If WindowState vbMinimized Then
GrabFrame
Width = ScaleX(Picture.Width, vbHimetric, vbTwips)
Height = ScaleY(Picture.Height, vbHimetric, vbTwips)
lblQuit.Move ScaleWidth - lblQuit.Width
lblPaused.Move ScaleWidth - lblPaused.Width, ScaleHeight - lblPaused.Height
chkPaused.Move lblPaused.Left - chkPaused.Width - 3, lblPaused.Top
End If
Running = False
End Sub

Private Sub lblQuit_Click()
Unload Me
End Sub

Private Sub lblSize_Click()
SendMessage mCapHwnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0
Form_Resize
End Sub

Private Sub lblSource_Click()
SendMessage mCapHwnd, WM_CAP_DLG_VIDEOSOURCE, 0, 0
Form_Resize
End Sub

Private Sub Timer1_Timer()
GrabFrame
End Sub

Private Sub GrabFrame()
On Error Resume Next
SendMessage mCapHwnd, WM_CAP_GRAB_FRAME, 0, 0
SendMessage mCapHwnd, WM_CAP_EDIT_COPY, 0, 0
Set Picture = Clipboard.GetData
End Sub

Private Sub lblPaused_Click()
chkPaused.Value = IIf(chkPaused.Value = 0, 1, 0)
End Sub

Private Sub chkPaused_Click()
If chkPaused.Value = 1 Then
LivePreview = False
Else
LivePreview = True
End If
End Sub

Friend Property Let LivePreview(ByVal b As Boolean)
'Toggle video on or off
If b = False Then
'Turn off video
If mLivePreview = True Then
SendMessage mCapHwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0
End If
Else
'Turn on video
If mLivePreview = False Then
SendMessage mCapHwnd, WM_CAP_DRIVER_CONNECT, 0, 0
End If
End If
mLivePreview = b
Timer1.Enabled = b
End Property

from the ass of the world
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

I have taken some time and port a bit of the code to Pure.
It only compiles it with no errors but did'nt work(a few stuff is missing) .Its just an example how to convert some stuff from VB to Pure.

Code: Select all

;Constants
#WM_CAP_DRIVER_CONNECT  = 1034
#WM_CAP_DRIVER_DISCONNECT  = 1035
#WM_CAP_GRAB_FRAME  = 1084
#WM_CAP_EDIT_COPY  = 1054
#WM_CAP_DLG_VIDEOFORMAT  = 1065
#WM_CAP_DLG_VIDEOSOURCE  = 1066
#WM_CLOSE = $10
#True=-1
#False=0

;Variables
mCapHwnd.l
mLivePreview.b

;Globals
Global DLLHandle
DLLHandle=OpenLibrary(1,"avicap32.dll" )
;Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
CapCreateCaptureWindowHandle=IsFunction(1, "capCreateCaptureWindowA") 

Procedure Form_MouseDown()    ;Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture_()
SendMessage_(hwnd, $A1, 2, 0)
EndProcedure

Procedure lblSize_Click()
SendMessage_( mCapHwnd, #WM_CAP_DLG_VIDEOFORMAT, 0, 0)
EndProcedure

Procedure lblSource_Click()
SendMessage_(mCapHwnd, #WM_CAP_DLG_VIDEOSOURCE, 0, 0)
EndProcedure


Procedure GrabFrame()
SendMessage_( mCapHwnd,#WM_CAP_GRAB_FRAME, 0, 0)
SendMessage_(mCapHwnd, #WM_CAP_EDIT_COPY, 0, 0)
;Set Picture = Clipboard.GetData ;Don't know how to handle
EndProcedure

 ;Form_Load()
 hwnd= OpenWindow(0, 100, 100, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
If hwnd0 
 mCapHwnd = CallFunctionFast(CapCreateCaptureWindowHandle,"My Own Capture 
Window", 0, 0, 0, 320, 240,hwnd, 0)
 LivePreview = True
 
 Repeat
    EventID.l = WaitWindowEvent()

    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf
; Form_Unload(Cancel As Integer)
LivePreview = #False
SendMessage_( mCapHwnd, #WM_CLOSE, 0, 0)
CloseLibrary(1)
End
Its a long way to the top if you wanna .....CodeGuru

Edited by - Rings on 07 May 2002 15:52:54
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Would this be a correct translation?:

Code: Select all

;Set Picture = Clipboard.GetData ;Don't know how to handle
Picture = GetClipboardData(#PB_ClipboardImage)
Also, I think mCapHwnd and hwnd should be global, since they're used in the procedures, or the procedures should accept them as parameters. Anyway, the code does quite nothing, does it? The procedures are not called, how to figure out when and in which order they should be called? Isn't something missing here? (or maybe not, I've never coded in VB).

Bye,


El_Choni
Post Reply