Copy picture files from camera

Posted on 2006-05-19
Last Modified: 2010-08-05
I am creating a VB 6 application to copy picture files from a camera and save them on the local hard drive. The users of this program have limited computer knowledge so I am trying to make it as simple as possible. What I have written so far works fine as long as the camera shows up as a removable drive. In that case I use the use the Drive control and code to find a removable drive, then use the FileSystemObject to copy the files. Some cameras, most notably certain Kodak models do not appear as a removable drive. Instead they are listed under Cameras and Scanners in Windows Explorer. I am assuming that they are Twain devices. In code, how can I access these cameras to copy the picture files?

Thanks in advance for any help.

Question by:bikertz
    LVL 8

    Expert Comment

    I can not guarantee this, but I believe you would have to write code for each camera.  Chances are they do not show up as
    removable drives because they require their own drivers.  If this is the case, you will need to write code to work with each
    set of drivers in order to access the camera.
    LVL 6

    Expert Comment

    To access twain32 devices, you need to use the KODAK image scan control, which used to be a component of Windows 2000 and lower versions, but not Windows XP. I used to have that control's windows XP version, but I might not be able to find it.

    Alternatively, you can also use some third-party ActiveX controls. I think there might be a free control named "EasyScan", which works well in both Windows XP and lower versions. Try to find it.

    Author Comment

    Thanks for the input. I'll check out the EasyScan control and see if I can find it. Let me know if you can find the Kodak control.


    Author Comment

    I did find a control distributed by Microsoft, Windows Image Acquisition Library, which I may be able to use for what I want to do, though it will only work with Windows XP, SP 1 or later. Has anyone used this control to simply download pictures from a camera and save them to the local c drive? The code example that accompanies the control gives an example of loading an image onto a form and manipulating that image. I'm not interested in that part of the control. I only want to download and save the pictures.


    Author Comment

    With the Windows Image Acquisition Library I was able to do exactly what I wanted to do with downloading pictures. I will post example code at a later date. Thanks to all who responded.
    LVL 8

    Expert Comment

    No objections here, unless Bikertz can come up with that example code, then you can accept his answer.

    Author Comment

    As promised, below is the code I used to download the pics.

    After downloading and installing Microsoft Windows Image Acquisition Library v2.0 from Microsoft's web site, I added the Component to my VB project.

    When user selects Download Pictures menu option, I confirm that the user has connected the camera and turned it on.

    dmMain is the Device Manager component of WIA library on the main form.

        strTemp = "Before downloading pictures from the camera to the selected project folder, " _
                  & "the camera must be connected to the computer and turned on. " _
                  & "Is the camera connected and turned on?"
        intResp = MsgBox(strTemp, vbQuestion + vbYesNo + vbDefaultButton2, "Download Pictures")
        If intResp = vbYes Then
          If dmMain.DeviceInfos.Count = 0 Then
            'no devices found, use form displaying available drives on computer
            frmDownloadPics.Show vbModal
            Screen.MousePointer = vbHourglass
            blnCamera = False
           'Device has been found, loop thru devices to determine if camera is connected
            For i = 1 To dmMain.DeviceInfos.Count
              If dmMain.DeviceInfos(i).Type = CameraDeviceType Then
                blnCamera = True
                Exit For
              End If
            'if camera found show camera form, otherwise default form listing available drives
            If blnCamera Then
              frmDownLoadPics_Camera.Show vbModal
              frmDownloadPics.Show vbModal
            End If
          End If
        End If

    In Form Load event of download Pics form, user is presented with two list boxes, one with devices attached
    and the other with list of files on attached devices

      'wiaDM is the Device Manager component added to the form
      If wiaDM.DeviceInfos.Count = 0 Then
        lstDev.AddItem "No Devices Available"
        For i = 1 To wiaDM.DeviceInfos.Count
          lstDev.AddItem wiaDM.DeviceInfos(i).Properties("Name").Value
          lstDev.ItemData(lstDev.NewIndex) = i
      End If

    When the user selects the camera device, display the picture file names in a list box

      For Each Itm In mDevice.Items
        lstPics.AddItem Itm.Properties("Item Name").Value & ".jpg"

    After determining that the user has selected at least one picture file name for download,
    read thru the selected items and copy the picture files to the designated folder on the hard drive

        Dim i As Integer, Itm As Item, Img As ImageFile
        Dim fs As FileSystemObject, strTemp As String, strSplit() As String, strPicFileName As String
        Dim strPicFolder As String
        For i = 0 To lstPics.ListCount - 1
            If lstPics.Selected(i) Then
              Set Itm = mDevice.Items(i + 1)
              Set Img = Itm.Transfer
              strPicFileName = Itm.Properties("Item Name").Value & "." & Img.FileExtension
              'if file name already exists in destination folder, append a 0 to the file name
              'Backslash function is a user defined function that makes sure a backslash character is at the end of the string
              'passed to it
              'DirTo is a DirListBox control
              If fs.FileExists(Backslash(DirTo.Path) & strPicFileName) Then
                strSplit = Split(strPicFileName, ".")
                strTemp = strSplit(0) & "0" & "." & strSplit(1)
                Do While fs.FileExists(Backslash(DirTo.Path) & strTemp)
                  strSplit = Split(strTemp, ".")
                  strTemp = strSplit(0) & "0" & "." & strSplit(1)
                MsgBox "Picture file name " & strPicFileName & " already exists, will be renamed to " _
                        & strTemp & ".", vbOKOnly + vbExclamation, "Picture File Name Exists"
                lblMsg.Caption = "Copying picture file " & strTemp & "..."
                strPicFileName = strTemp
              End If
              'display to user file being downloaded
              lblMsg.Caption = "Copying picture file " & strPicFileName & "..."
              Img.SaveFile Backslash(DirTo.Path) & strPicFileName
              FileTo.ListIndex = FindFileInFileList(strPicFileName, FileTo)
            End If
          Next i


    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now