• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Copy picture files from camera

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.

Tommy
0
bikertz
Asked:
bikertz
1 Solution
 
List244Commented:
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.
0
 
junglerover77Commented:
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.
0
 
bikertzAuthor Commented:
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.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bikertzAuthor Commented:
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.

Tommy
0
 
bikertzAuthor Commented:
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.
0
 
List244Commented:
No objections here, unless Bikertz can come up with that example code, then you can accept his answer.
0
 
bikertzAuthor Commented:
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
      Else
        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
        Next
        'if camera found show camera form, otherwise default form listing available drives
        If blnCamera Then
          frmDownLoadPics_Camera.Show vbModal
        Else
          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
  lstDev.Clear
  If wiaDM.DeviceInfos.Count = 0 Then
    lstDev.AddItem "No Devices Available"
  Else
    For i = 1 To wiaDM.DeviceInfos.Count
      lstDev.AddItem wiaDM.DeviceInfos(i).Properties("Name").Value
      lstDev.ItemData(lstDev.NewIndex) = i
    Next
  End If

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

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

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)
            Loop
            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
            DoEvents
          End If
          'display to user file being downloaded
          lblMsg.Caption = "Copying picture file " & strPicFileName & "..."
          DoEvents
          Img.SaveFile Backslash(DirTo.Path) & strPicFileName
          FileTo.Refresh
          FileTo.ListIndex = FindFileInFileList(strPicFileName, FileTo)
        End If
      Next i

0
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now