none
Avoiding the Video Source Window.

    Question

  • Hi there.

    How can I avoid using the Video Source window?

    I need the Logitech HD Webcam C310 to be preselected.

    When the Main Form opens the Webcam must be running allready, withoute having to select it from the Video Source Window.

    Can this be done and How?


    Hendri Bissolati noviceprogrammer@vodamail.co.za


    Thursday, May 17, 2012 9:46 AM

Answers

  • I have solved the saving problem by devizing a work around.

    Here is the revized main form code.

    Option Explicit On
    'Option Strict On
    Imports System.Text.RegularExpressions
    Public Class MainForm
        Inherits System.Windows.Forms.Form
        Friend WithEvents PictureCropper As New PictureCropper With {.Dock = DockStyle.Fill}
        'Friend WithEvents OpenFileDialog As New OpenFileDialog With {.CheckFileExists = True, .Filter = "Image Files|*.bmp;*.png;*.gif;*.tif;*.jpg", .Title = "Open Source Image"}
        Friend WithEvents SaveFileDialog As New SaveFileDialog With {.AddExtension = True, .DefaultExt = "bmp", .Filter = "Bitmap|*.bmp|Portable Network Graphics|*.png|JPEG|*.jpg", .Title = "Save Cropped Image"}
        Private myCam As iCam
        Private Property getNumbers As Char
        Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myCam = New iCam
            myCam.initCam(Me.PreViewPictureBox.Handle.ToInt32)
        End Sub
        Public MeText As String = "PreViewing"
        Private Sub tmrUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdate.Tick
            If MeText = "PreViewing" Then
                Me.Text = ("DIY ID      " & MeText & " at " & myCam.FPS & " frames per second.")
            Else
                Me.Text = ("DIY ID      " & MeText)
            End If
        End Sub
    #Region "User Input Controls"
        'Public CurrentFilePath As String
        Function cleanup(StrInput As String) As String
            Dim rgPattern = "[\\\/:\*\?""'<>|]"
            Dim objRegEx As New Regex(rgPattern)
            Return Replace(objRegEx.Replace(StrInput, "-"), " ", " ")
        End Function
        Dim CurrentFilePath As String = ""
        Dim StrInput As String = Now.ToString
        Dim NewFolder As String = (cleanup(StrInput))
        'Dim NewDirectory As String = IO.Path.Combine("D:\DIY.ID Photos", NewFolder)
        Dim NewDirectory As String
        Dim NewImage As String
        Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureButton.Click, CropButton.Click, PreViewButton.Click, OpenFileButton.Click, SaveButton.Click, PrintButton.Click
            If sender Is PictureButton Then
                PictureBox1.Visible = True
                PictureBox1.Location = New Point(144, 0)
                PictureBox1.Size = New Size(640, 450)
                PictureBox1.Image = myCam.copyFrame(Me.PreViewPictureBox, New RectangleF(0, 0, Me.PreViewPictureBox.Width, Me.PreViewPictureBox.Height))
                Try   '<<< Creating New Folder and Saving Image to that Folder.>>>
                    If (PictureBox1.Image IsNot Nothing) Then
                        NewDirectory = IO.Path.Combine("D:\DIY.ID Photos", NewFolder)
                        IO.Directory.CreateDirectory(NewDirectory)
                        NewImage = IO.Path.Combine(NewDirectory, "PreView Photo.bmp")
                        CurrentFilePath = NewDirectory
                        PictureBox1.Image.Save(NewImage)
                        MsgBox("PreView Picture Saved Sucsesfully.")
                        MeText = "Picture Ready to be Cropped."
                    End If
                Catch ex As Exception
                    MsgBox("Problem Saving PreView Picture.")
                End Try
                PreViewPictureBox.Visible = False
                '<<< Enableing and Disableing Buttont as needed.>>>
                PictureButton.Enabled = False
                CropButton.Enabled = True
                PreViewButton.Enabled = True
                OpenFileButton.Enabled = False
                SaveButton.Enabled = False
                'PrintButton.Enabled = False
            End If
            If sender Is CropButton Then
                Controls.Add(PictureCropper)
                MeText = "Cropping Picture."
                PictureCropper.Picture = PictureBox1.Image
                PictureBox1.Visible = False
                '<<< Enableing and Disableing Buttont as needed.>>>
                'PictureButton.Enabled = True
                CropButton.Enabled = False
                'PreViewButton.Enabled = False
                'OpenFileButton.Enabled = True
                SaveButton.Enabled = True
                'PrintButton.Enabled = False
            End If
            If sender Is PreViewButton Then
                MeText = "PreViewing"
                '<<< Code for canceling operation and going back to PreView must go here.>>>
            End If
            If sender Is OpenFileButton Then
                '<<< Code for opening Image File from removable device must go here.>>>
            End If
            If sender Is SaveButton Then
                Try    '<<< The thing I am trying to do here is to get "Cropped Photo.bmp" saved
                    '       '<<< into the same Folder as where "PreView Photo.bmp" is saved during the PictureButton.Click event.    
                    MeText = "Saveing Cropped Picture."
                    Panel.Visible = True
                    NewImage = IO.Path.Combine(NewDirectory, "Cropped Photo.bmp")
                    PictureCropper.Crop.Save(NewImage)
                    MeText = "Photos Ready to be Printed."
                Catch ex As Exception
                    MsgBox("Problem Saving Cropped Picture.")
                End Try
                MeText = "Photos Ready to be Printed."
                '<<< Enableing and Disableing Buttont as needed.>>>
                'PictureButton.Enabled = False
                'CropButton.Enabled = True
                'PreViewButton.Enabled = False
                'OpenFileButton.Enabled = False
                'SaveButton.Enabled = False
                PrintButton.Enabled = True
                PictureCropper.Dispose()
                PictureBox1.Visible = True
                PictureBox1.Location = New Point(165, 23)
                PictureBox1.Size = New System.Drawing.Size(100, 139)
                PictureBox1.Image = Image.FromFile(NewImage)
                PictureBox2.Visible = True
                PictureBox2.Location = New Point(287, 23)
                PictureBox2.Image = PictureBox1.Image
                PictureBox3.Visible = True
                PictureBox3.Location = New Point(165, 183)
                PictureBox3.Image = PictureBox1.Image
                PictureBox4.Visible = True
                PictureBox4.Location = New Point(287, 183)
                PictureBox4.Image = PictureBox1.Image
            End If
            If sender Is PrintButton Then
                '<<< Code for Printing must go here.>>>
            End If
        End Sub
    #End Region
    End Class


    Hendri Bissolati

    Saturday, May 26, 2012 5:52 AM

All replies

  • Are you using amcap? it has code in the windows sdk for windows 7 but its in c++. I would try seeing if you can see if it has any command line switchs built into it or you can just add one in c++ code to preselect your device using commmand line and compile the amcap program. I believe it was under directshow folder in windows 7 sdk when installed.

    After compiling amcap with command line in c++ then call from vb.net which makes life easier because commandline parameters are easier in c++ and this method would take the least work.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    • Proposed as answer by The Thinker Thursday, May 17, 2012 12:22 PM
    • Unproposed as answer by The Thinker Thursday, May 17, 2012 1:08 PM
    • Proposed as answer by The Thinker Thursday, May 17, 2012 1:08 PM
    • Unproposed as answer by Hendri Bissolati Thursday, May 17, 2012 3:38 PM
    Thursday, May 17, 2012 12:22 PM
  • for more help please go to wdk forum and ask for assistance because video feeds get technical and they can answer you a lot faster then anyone in vb.net forum or suggest windows apis:

    http://social.msdn.microsoft.com/Forums/en-US/wdk/threads

    Ask about openfile and they will give you an example of what i was talking about in other thread it would be a little similar in vb.net

    Also, directshow forum here:

    http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/threads


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/




    • Proposed as answer by The Thinker Thursday, May 17, 2012 1:08 PM
    • Edited by The Thinker Thursday, May 17, 2012 1:08 PM
    • Unproposed as answer by Hendri Bissolati Thursday, May 17, 2012 3:38 PM
    Thursday, May 17, 2012 1:07 PM
  • for more help please go to wdk forum and ask for assistance because video feeds get technical and they can answer you a lot faster then anyone in vb.net forum or suggest windows apis:

    http://social.msdn.microsoft.com/Forums/en-US/wdk/threads

    Ask about openfile and they will give you an example of what i was talking about in other thread it would be a little similar in vb.net

    Also, directshow forum here:

    http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/threads


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/




    Here is the code I am using, Bits and peases off the internett.  There might even be redundent code as I cut out the peases I do not nead.  I am working through this code to try and understand what code is doing what.

    I hope this helps you to help me?

    Option Explicit On
    Option Strict On
    Public Class MainForm
        Inherits System.Windows.Forms.Form
        Private myCam As iCam
        Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myCam = New iCam
            myCam.initCam(Me.PreViewerPictureBox.Handle.ToInt32)
        End Sub
    #Region "User Interface"
        Private Sub TakePhotoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TakePhotoButton.Click
            PhotoBox.Image = myCam.copyFrame(Me.PreViewerPictureBox, New RectangleF(0, 0, Me.PreViewerPictureBox.Width, Me.PreViewerPictureBox.Height))
           
        End Sub
    #End Region
    End Class

    Option Explicit On
    Option Strict On
    Public Class iCam
    #Region "Api/constants"
        Private Const WS_CHILD As Integer = &H40000000
        Private Const WS_VISIBLE As Integer = &H10000000
        Private Const SWP_NOMOVE As Short = &H2S
        Private Const SWP_NOZORDER As Short = &H4S
        Private Const WM_USER As Short = &H400S
        Private Const WM_CAP_DRIVER_CONNECT As Integer = WM_USER + 10
        Private Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_USER + 11
        Private Const WM_CAP_SET_VIDEOFORMAT As Integer = WM_USER + 45
        Private Const WM_CAP_SET_PREVIEW As Integer = WM_USER + 50
        Private Const WM_CAP_SET_PREVIEWRATE As Integer = WM_USER + 52
        Private Const WM_CAP_GET_FRAME As Long = 1084
        Private Const WM_CAP_COPY As Long = 1054
        Private Const WM_CAP_START As Long = WM_USER
        Private Const WM_CAP_STOP As Long = (WM_CAP_START + 68)
        Private Const WM_CAP_SEQUENCE As Long = (WM_CAP_START + 62)
        Private Const WM_CAP_SET_SEQUENCE_SETUP As Long = (WM_CAP_START + 64)
        Private Const WM_CAP_FILE_SET_CAPTURE_FILEA As Long = (WM_CAP_START + 20)
        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Short, ByVal lParam As String) As Integer
        Private 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 Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
        Private Declare Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Int32) As Boolean
    #End Region
        Private iDevice As String
        Private hHwnd As Integer
        Private lwndC As Integer
        Public iRunning As Boolean
        Private CamFrameRate As Integer = 15
       
        Public Sub initCam(ByVal parentH As Integer)
            Dim OutputWidth As Integer = 470
            Dim OutputHeight As Integer = 350
            'Gets the handle and initiates camera setup
            If Me.iRunning = True Then
                MessageBox.Show("Camera Is Already Running")
                Exit Sub
            Else
                hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, OutputWidth, CShort(OutputHeight), parentH, 0)
                If setCam() = False Then
                    MessageBox.Show("Error setting Up Camera")
                End If
            End If
        End Sub
        Private Function setCam() As Boolean
            'Sets all the camera up
            If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, CShort(iDevice), CType(0, String)) = 1 Then
                SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, CShort(CamFrameRate), CType(0, String))
                SendMessage(hHwnd, WM_CAP_SET_PREVIEW, 1, CType(0, String))
                Me.iRunning = True
                Return True
            Else
                Me.iRunning = False
                Return False
            End If
        End Function
        Public Function copyFrame(ByVal src As PictureBox, ByVal rect As RectangleF) As Bitmap
            Dim srcPic As Graphics = src.CreateGraphics
            Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
            Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
            Dim HDC1 As IntPtr = srcPic.GetHdc
            Dim HDC2 As IntPtr = srcMem.GetHdc
            BitBlt(HDC2, 0, 0, CInt(rect.Width), _
              CInt(rect.Height), HDC1, CInt(rect.X), CInt(rect.Y), 13369376)
            copyFrame = CType(srcBmp.Clone(), Bitmap)
            srcPic.ReleaseHdc(HDC1)
            srcMem.ReleaseHdc(HDC2)
            srcPic.Dispose()
            srcMem.Dispose()
        End Function
        Public Function FPS() As Integer
            Return CInt(1000 / (CamFrameRate))
        End Function
    End Class


    Hendri Bissolati noviceprogrammer@vodamail.co.za

    Thursday, May 17, 2012 3:36 PM
  •   Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
    the above code section i posted i believe sets up bitmap with that width and height.

    The below code does some screen operation to play on the screen or form (its a directx operation):

       BitBlt(HDC2, 0, 0, CInt(rect.Width), _
             
    CInt(rect.Height), HDC1, CInt(rect.X), CInt(rect.Y), 13369376)

    or it might just copy the bitmap data into memory.

    This code is probably what creates the window you dont want because it has an hwnd variable which usually stands for window handles. If i knew a way to automatically select the device from combo box and then click the button to start capturing I would share that.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/




    Thursday, May 17, 2012 4:25 PM
  • I don't want the user to have to select the WebCam from the Video Soue Window and then have to click Apply and Ok.  I need this to be done via. code without even having to see the Video Soue Window.


    Hendri Bissolati

    Saturday, May 19, 2012 9:41 AM
  • Hendri,

    We have a sample around this on our webcam, I know that it does what it has to done, but it is a piece of old code Ken provided, I know little about it and in my idea it is already in this thread.

    http://www.vb-tips.com/Webcam.aspx

     I know that it works because I've edited the code lately to make it look nicer, but did not look real at it. Win32 api's are not my favorites.

    But you can create a new project and copy and past it, that is the same I did with this code and nothing more.


    Success
    Cor


    Saturday, May 19, 2012 10:48 AM
  • Thanks Cor I will have a go at it.


    Hendri Bissolati

    Saturday, May 19, 2012 11:16 AM
  • When ranning this code for the first time the Listbox is populated with only one device, "Microsoft WDM Image Capture (Win32)" selecting that and clicking on Start the Video Source Window pops up, when the Webcam is selected it works the same as in my app. 

    Click Stop and click Start again it works without the Video Source Window poping up.  This tels me that somewhere in a Var this info is stored, I can not find it. 

    How can I find this?


    Hendri Bissolati

    Saturday, May 19, 2012 12:47 PM
  • in cor's link above it has it commented where it loads the list of devices into the listbox. how about you take bReturn in below code and pass to correct function to just directly use webcam?

       '
                '   Get Driver name and version
                '
                bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
                '
                ' If there was a device add device name to the list
    Thats the device information

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    • Proposed as answer by The Thinker Saturday, May 19, 2012 3:42 PM
    Saturday, May 19, 2012 3:42 PM
  • Thanks Thinker.

    It is just that Function that I do not know how to do.


    Hendri Bissolati

    Saturday, May 19, 2012 3:50 PM
  • Okay I will take another 30 minutes because im having to write apa papers or maybe longer depending on code difficulty. I tend to think creatively so some problems are not hard for me and some easy ones sometimes drive me crazy  and then I find them and clam back down. An example would be that one line of code i cant seem to find but shows an error on runtime. But best one is active directory giving generic error messages and oh didn that hurt when it was a simple fix.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    Saturday, May 19, 2012 4:15 PM
  • copy the code from the start button here and change it:

       Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            DeviceID = lstDevices.Items(0)
            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

    I will check the openpreviewwindows method because it might be making you select from listbox but instead do lstDevices.Items(i) which presets to certain item on listbox like if theirs only one item on listbox make i = 0 or replace i with 0.

    Looks like you can just start capturing video if you do my suggestion and it DeviceID that is the number for that device sorry for any confusion.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/



    • Proposed as answer by The Thinker Saturday, May 19, 2012 4:27 PM
    • Edited by The Thinker Saturday, May 19, 2012 4:31 PM
    Saturday, May 19, 2012 4:24 PM
  • BTW, i thank cor for that update to the code because it helps me too later except I will be doing with kinect for windows which already has functions setup for capturing video from device in image box.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    Saturday, May 19, 2012 4:32 PM
  • Tryed that, stil the same. Don't be in to much of a hurry to mark my posts as answer, I'm learning.

    I am working on difersnt sections of code in this app.  I want to tidy up a bit then I wil put the hole project on SkyDrive so You, Cor and others can have a look at it.  I am planing to post it out there when finished enyway.


    Hendri Bissolati

    Saturday, May 19, 2012 5:27 PM
  • Yes tell us what you need and we will help you further.

    OpenPreviewWindow() function displays the preview of the video from looking at code and comments and so now you can make the listbox invisible by going lstDevices.visible  = false. Place the start button code into formnamehere_load event so you can have it startup the app without any intervention with selecting the camera you need or you can have them select once but you need manual modification of code and some writing to a file. Also, make the button named btnStart invisible by changing its visible property to false also.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/




    Saturday, May 19, 2012 5:38 PM
  • I tryed the code it wont load any devices for me and that might be the fact that i have a integrated webcam that only comes on when requested to. So i wont know for sure unless kinect filter shows up in list or i test with another device.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/




    Saturday, May 19, 2012 6:02 PM
  • Give me a day or 2, we will discus this point and others futher.

    Thanks for your pationts.


    Hendri Bissolati

    Saturday, May 19, 2012 6:09 PM
  • give us an update.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    Wednesday, May 23, 2012 1:26 PM
  • Hi there Thinker.

    I am not egnoring you, I'm still busy cleering up and so on.  I'm going to put the project on SkyDrive so you can beter help me.

    Watch this space.  Thanks for your interist.


    Hendri Bissolati

    Wednesday, May 23, 2012 5:06 PM
  • Here is a link to the project as promest.  DIY.ID Photo


    Hendri Bissolati

    Friday, May 25, 2012 5:12 AM
  • It seems to be a bug or something in the way the class is called but if I restart the app after disabling and reenabling my camera it doesnt ask for the camera selection box.  Thanks for the code though I might see if I can find out whats causing the GDI error though. But I think something is amiss in your cropping code because the normal picture saves fine. So make sure the camera is plugged in well when taking pictures. 

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    Friday, May 25, 2012 8:20 PM
  • I have solved the saving problem by devizing a work around.

    Here is the revized main form code.

    Option Explicit On
    'Option Strict On
    Imports System.Text.RegularExpressions
    Public Class MainForm
        Inherits System.Windows.Forms.Form
        Friend WithEvents PictureCropper As New PictureCropper With {.Dock = DockStyle.Fill}
        'Friend WithEvents OpenFileDialog As New OpenFileDialog With {.CheckFileExists = True, .Filter = "Image Files|*.bmp;*.png;*.gif;*.tif;*.jpg", .Title = "Open Source Image"}
        Friend WithEvents SaveFileDialog As New SaveFileDialog With {.AddExtension = True, .DefaultExt = "bmp", .Filter = "Bitmap|*.bmp|Portable Network Graphics|*.png|JPEG|*.jpg", .Title = "Save Cropped Image"}
        Private myCam As iCam
        Private Property getNumbers As Char
        Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myCam = New iCam
            myCam.initCam(Me.PreViewPictureBox.Handle.ToInt32)
        End Sub
        Public MeText As String = "PreViewing"
        Private Sub tmrUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdate.Tick
            If MeText = "PreViewing" Then
                Me.Text = ("DIY ID      " & MeText & " at " & myCam.FPS & " frames per second.")
            Else
                Me.Text = ("DIY ID      " & MeText)
            End If
        End Sub
    #Region "User Input Controls"
        'Public CurrentFilePath As String
        Function cleanup(StrInput As String) As String
            Dim rgPattern = "[\\\/:\*\?""'<>|]"
            Dim objRegEx As New Regex(rgPattern)
            Return Replace(objRegEx.Replace(StrInput, "-"), " ", " ")
        End Function
        Dim CurrentFilePath As String = ""
        Dim StrInput As String = Now.ToString
        Dim NewFolder As String = (cleanup(StrInput))
        'Dim NewDirectory As String = IO.Path.Combine("D:\DIY.ID Photos", NewFolder)
        Dim NewDirectory As String
        Dim NewImage As String
        Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureButton.Click, CropButton.Click, PreViewButton.Click, OpenFileButton.Click, SaveButton.Click, PrintButton.Click
            If sender Is PictureButton Then
                PictureBox1.Visible = True
                PictureBox1.Location = New Point(144, 0)
                PictureBox1.Size = New Size(640, 450)
                PictureBox1.Image = myCam.copyFrame(Me.PreViewPictureBox, New RectangleF(0, 0, Me.PreViewPictureBox.Width, Me.PreViewPictureBox.Height))
                Try   '<<< Creating New Folder and Saving Image to that Folder.>>>
                    If (PictureBox1.Image IsNot Nothing) Then
                        NewDirectory = IO.Path.Combine("D:\DIY.ID Photos", NewFolder)
                        IO.Directory.CreateDirectory(NewDirectory)
                        NewImage = IO.Path.Combine(NewDirectory, "PreView Photo.bmp")
                        CurrentFilePath = NewDirectory
                        PictureBox1.Image.Save(NewImage)
                        MsgBox("PreView Picture Saved Sucsesfully.")
                        MeText = "Picture Ready to be Cropped."
                    End If
                Catch ex As Exception
                    MsgBox("Problem Saving PreView Picture.")
                End Try
                PreViewPictureBox.Visible = False
                '<<< Enableing and Disableing Buttont as needed.>>>
                PictureButton.Enabled = False
                CropButton.Enabled = True
                PreViewButton.Enabled = True
                OpenFileButton.Enabled = False
                SaveButton.Enabled = False
                'PrintButton.Enabled = False
            End If
            If sender Is CropButton Then
                Controls.Add(PictureCropper)
                MeText = "Cropping Picture."
                PictureCropper.Picture = PictureBox1.Image
                PictureBox1.Visible = False
                '<<< Enableing and Disableing Buttont as needed.>>>
                'PictureButton.Enabled = True
                CropButton.Enabled = False
                'PreViewButton.Enabled = False
                'OpenFileButton.Enabled = True
                SaveButton.Enabled = True
                'PrintButton.Enabled = False
            End If
            If sender Is PreViewButton Then
                MeText = "PreViewing"
                '<<< Code for canceling operation and going back to PreView must go here.>>>
            End If
            If sender Is OpenFileButton Then
                '<<< Code for opening Image File from removable device must go here.>>>
            End If
            If sender Is SaveButton Then
                Try    '<<< The thing I am trying to do here is to get "Cropped Photo.bmp" saved
                    '       '<<< into the same Folder as where "PreView Photo.bmp" is saved during the PictureButton.Click event.    
                    MeText = "Saveing Cropped Picture."
                    Panel.Visible = True
                    NewImage = IO.Path.Combine(NewDirectory, "Cropped Photo.bmp")
                    PictureCropper.Crop.Save(NewImage)
                    MeText = "Photos Ready to be Printed."
                Catch ex As Exception
                    MsgBox("Problem Saving Cropped Picture.")
                End Try
                MeText = "Photos Ready to be Printed."
                '<<< Enableing and Disableing Buttont as needed.>>>
                'PictureButton.Enabled = False
                'CropButton.Enabled = True
                'PreViewButton.Enabled = False
                'OpenFileButton.Enabled = False
                'SaveButton.Enabled = False
                PrintButton.Enabled = True
                PictureCropper.Dispose()
                PictureBox1.Visible = True
                PictureBox1.Location = New Point(165, 23)
                PictureBox1.Size = New System.Drawing.Size(100, 139)
                PictureBox1.Image = Image.FromFile(NewImage)
                PictureBox2.Visible = True
                PictureBox2.Location = New Point(287, 23)
                PictureBox2.Image = PictureBox1.Image
                PictureBox3.Visible = True
                PictureBox3.Location = New Point(165, 183)
                PictureBox3.Image = PictureBox1.Image
                PictureBox4.Visible = True
                PictureBox4.Location = New Point(287, 183)
                PictureBox4.Image = PictureBox1.Image
            End If
            If sender Is PrintButton Then
                '<<< Code for Printing must go here.>>>
            End If
        End Sub
    #End Region
    End Class


    Hendri Bissolati

    Saturday, May 26, 2012 5:52 AM
  • Dear Sir,

    Will you please give some steps to run your given code, so that we can run and solve the above issue in our application.

    I am newbie for the VB Programming, If we want to run your code in C# then is it possible? Our whole application is in C#.Net which runs on Win XP OS perfectly but not working with Windows 7 os and gives the Video source dialog box.

    Suggest us if you have any other way to solve the above issue.

    Please reply me as your earliest.

    Thanks in advance.

    -Programmer

    Thursday, January 10, 2013 1:06 PM