Results 1 to 8 of 8

Thread: Draw On Camera Preview screen in VB2010

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Exclamation Draw On Camera Preview screen in VB2010

    Hello everyone,

    Hope you all the doing awesome !!

    Name:  drawoncam.jpg
Views: 276
Size:  18.1 KB



    I am working on capturing video via accessing the camera of my laptop in visual basic 2010. the code works fine but when I try to draw any shape on it- my code just do not work - no error but there is no shape. I think i do not know how to draw on camera preview screen.


    here is my code-


    Code:
     Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            DeviceID = lstDevices.SelectedIndex
            OpenPreviewWindow()
            Dim bReturn As Boolean
            Dim s As CAPSTATUS
            bReturn = SendMessage(hHwnd, WM_CAP_GET_STATUS, Marshal.SizeOf(s), s)
            Debug.WriteLine(String.Format("Video Size {0} x {1}", s.uiImageWidth, s.uiImageHeight))
        End Sub
    
    
    Private Sub btnInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInfo.Click
            Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
            Dim formGraphics As System.Drawing.Graphics
            formGraphics = Me.CreateGraphics()
            formGraphics.FillRectangle(myBrush, New Rectangle(50, 9, 200, 30))
            picCapture.SendToBack()
            ' SendMessage(hHwnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
            SendMessage(hHwnd, WM_CAP_DLG_VIDEOFORMAT, True, 0)
        End Sub
    
      Private Sub Frm_camera_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LoadDeviceList()
            If lstDevices.Items.Count > 0 Then
                btnStart.Enabled = True
                lstDevices.SelectedIndex = 0
               btnStart.Enabled = True
            Else
                lstDevices.Items.Add("No Capture Device")
                btnStart.Enabled = False
            End If
    
            'Me.AutoScrollMinSize = New Size(100, 100)
            
            picCapture.SizeMode = PictureBoxSizeMode.StretchImage
        End Sub
    Last edited by si_the_geek; Jan 15th, 2021 at 12:37 PM. Reason: fixed formatting issue
    < / L R. . . . >

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Re: Draw On Camera Preview screen in VB2010

    The drawing code is in - button_info_click()>> help me with it. I do not know much to it
    < / L R. . . . >

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Re: Draw On Camera Preview screen in VB2010

    ohh come on >> Any one please a little help here ?
    < / L R. . . . >

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Draw On Camera Preview screen in VB2010

    Quote Originally Posted by lokesh R View Post
    ohh come on
    Maybe that's not the way to make people want to help. Bumping a thread that's a few hours old is seriously frowned on here. If your thread is still on the first page then there's no excuse to be bumping it.

    As for the issue, if you had done proper research then you'd know that you don't call CreateGraphics in order to do GDI+ drawing. Some people use that in examples for simplicity but you don't do it in a real application. Do your drawing on the Paint event of the control you want to draw on. In your case, I'd assume that that would be the PictureBox. You can follow the CodeBank link in my signature below and check out some of my GDI+ drawing threads for examples or research the Paint event elsewhere.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Re: Draw On Camera Preview screen in VB2010

    Quote Originally Posted by jmcilhinney View Post
    Maybe that's not the way to make people want to help. Bumping a thread that's a few hours old is seriously frowned on here. If your thread is still on the first page then there's no excuse to be bumping it.

    As for the issue, if you had done proper research then you'd know that you don't call CreateGraphics in order to do GDI+ drawing. Some people use that in examples for simplicity but you don't do it in a real application. Do your drawing on the Paint event of the control you want to draw on. In your case, I'd assume that that would be the PictureBox. You can follow the CodeBank link in my signature below and check out some of my GDI+ drawing threads for examples or research the Paint event elsewhere.
    I apologies for the comment and the attitude
    < / L R. . . . >

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Re: Draw On Camera Preview screen in VB2010

    Quote Originally Posted by lokesh R View Post
    I apologies for the comment and the attitude
    yes, I will try to do so but the problem is these are not just the images to be drawn over picturebox. this is a camera feeding to the picturebox so will that solution work ? i will try and confirm the same
    < / L R. . . . >

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Draw On Camera Preview screen in VB2010

    Quote Originally Posted by lokesh R View Post
    will that solution work ?
    I don't know, but it has a better chance of working than what you're doing now.

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2021
    Location
    Kepler-452b
    Posts
    37

    Re: Draw On Camera Preview screen in VB2010

    Quote Originally Posted by jmcilhinney View Post
    I don't know, but it has a better chance of working than what you're doing now.
    it darws the shpe but it erases as soon as the video comes in
    < / L R. . . . >

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width