4 Replies - 895 Views - Last Post: 30 June 2011 - 10:27 PM Rate Topic: -----

#1 sudeepta_mca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-June 11

The code for camera,given bellow not working properly,what should i do

Posted 29 June 2011 - 10:53 PM

Hello! I got the following code from net,its working sometimes but sometimes not working, why?Its not showing the video by every click of the button Preview.I want some better code which will work smoothly and will show the video by every click.Could you please help me as soon as possible??
With Regards Sudeepta.

CODING:-

' declaration for camera
    Const CAP As Short = &H400S
    Const CAP_DRIVER_CONNECT As Integer = CAP + 10
    Const CAP_DRIVER_DISCONNECT As Integer = CAP + 11
    Const CAP_EDIT_COPY As Integer = CAP + 30
    Const CAP_SET_PREVIEW As Integer = CAP + 50
    Const CAP_SET_PREVIEWRATE As Integer = CAP + 52
    Const CAP_SET_SCALE As Integer = CAP + 53
    Const WS_CHILD As Integer = &H40000000
    Const WS_VISIBLE As Integer = &H10000000
    Const SWP_NOMOVE As Short = &H2S
    Const SWP_NOSIZE As Short = 1
    Const SWP_NOZORDER As Short = &H4S
    Const HWND_BOTTOM As Short = 1
    Dim iDevice As Integer = 0 ' Normal device ID
    Dim hHwnd As Integer ' Handle value to preview window

'Declare function from AVI capture DLL.
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer

    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    
    Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
        ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
        ByVal nHeight As Short, ByVal hWndParent As Integer, _
        ByVal nID As Integer) As Integer

 Private Sub OpenForm()
        Dim iHeight As Integer = CameraPictureBox.Height
        Dim iWidth As Integer = CameraPictureBox.Width

        ' Open Preview window in picturebox .
        ' Create a child window with capCreateCaptureWindowA so you can display it in a picturebox.
        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, CameraPictureBox.Handle.ToInt32, 0)

        ' Connect to device
        If SendMessage(hHwnd, CAP_DRIVER_CONNECT, iDevice, 0) Then

            ' Set the preview scale
            SendMessage(hHwnd, CAP_SET_SCALE, True, 0)

            ' Set the preview rate in milliseconds
            SendMessage(hHwnd, CAP_SET_PREVIEWRATE, 66, 0)

            ' Start previewing the image from the camera
            SendMessage(hHwnd, CAP_SET_PREVIEW, True, 0)

            ' Resize window to fit in picturebox
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, CameraPictureBox.Width, CameraPictureBox.Height, SWP_NOMOVE Or SWP_NOZORDER)
        Else
            ' Error connecting to device close window
            DestroyWindow(hHwnd)
        End If
    End Sub

 Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
        ' Disconnect from device
        SendMessage(hHwnd, CAP_DRIVER_DISCONNECT, iDevice, 0)
        ' close window
        DestroyWindow(hHwnd)
    End Sub

 Private Sub btnCAPTURE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCAPTURE.Click
        Dim data As IDataObject
        Dim bmap As Image
        ' Copy image to clipboard
        SendMessage(hHwnd, CAP_EDIT_COPY, 0, 0)
        ' Get image from clipboard and convert it to a bitmap
        data = Clipboard.GetDataObject()

        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
            SendMessage(hHwnd, CAP_DRIVER_DISCONNECT, iDevice, 0)
            ' close window
            DestroyWindow(hHwnd)
            CameraPictureBox.Image = bmap
        End If
 End Sub

Private Sub btnPREVIEW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPREVIEW.Click
        OpenForm()
    End Sub


Mod Edit:
:code:

Is This A Good Question/Topic? 0
  • +

Replies To: The code for camera,given bellow not working properly,what should i do

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: The code for camera,given bellow not working properly,what should i do

Posted 30 June 2011 - 06:47 AM

Let me be clear on the summary - this is not your code. It's not working. You want us to determine why, or provide you with different code? Just a helpful reminder that's not how we operate here. We want you to grow as a developer, and would hate to have you miss out on great learning opportunities.

Can you elaborate on what is going on? Have you put a break points or debugged through the code?

Thank you for helping us to help you!
Was This Post Helpful? 0
  • +
  • -

#3 sudeepta_mca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-June 11

Re: The code for camera,given bellow not working properly,what should i do

Posted 30 June 2011 - 09:56 PM

View Postmodi123_1, on 30 June 2011 - 06:47 AM, said:

Let me be clear on the summary - this is not your code. It's not working. You want us to determine why, or provide you with different code? Just a helpful reminder that's not how we operate here. We want you to grow as a developer, and would hate to have you miss out on great learning opportunities.

Can you elaborate on what is going on? Have you put a break points or debugged through the code?

Thank you for helping us to help you!

Was This Post Helpful? 0
  • +
  • -

#4 sudeepta_mca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-June 11

Re: The code for camera,given bellow not working properly,what should i do

Posted 30 June 2011 - 10:15 PM

Yes, I have put a break points and debugged many times.I want to clear you that it doesn't give any error,it is running properly and few month ago it was showing the video by the 1st and 2nd click but further it didn't work.I stopped debugging,run again then it was working again like above,but recently i am trying to run again but it doesn't work by the 1st click.
I am not expert in window programming and i am a fresher in .Net programming so can you help me to develop this code. I know its need some few changes but where i am confused.
With regards!

View Postmodi123_1, on 30 June 2011 - 06:47 AM, said:

Let me be clear on the summary - this is not your code. It's not working. You want us to determine why, or provide you with different code? Just a helpful reminder that's not how we operate here. We want you to grow as a developer, and would hate to have you miss out on great learning opportunities.

Can you elaborate on what is going on? Have you put a break points or debugged through the code?

Thank you for helping us to help you!

Was This Post Helpful? 0
  • +
  • -

#5 sudeepta_mca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-June 11

Re: The code for camera,given bellow not working properly,what should i do

Posted 30 June 2011 - 10:27 PM

Another thing is that i didn't just copied and pasted this code,i had done some changes which my project was required because it was not working without these changes.I put the break point at the function- OpenForm(),when it goes to the "If" condition,it don't enter it and goes to the else part, thats why it doesn't show the video.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1