Solved

Using WIA and connecting to digital camera- need date/time of pic

Posted on 2011-03-06
5
1,055 Views
Last Modified: 2012-06-22
I've been using the code from this posting:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22493402.html

to successfully access my digital camera connected via USB to my PC. I can view the photos and move/copy to my PC.

I've been using WIA (Dim objWia As WIA.CommonDialog).

I would ilke to be able to access the date/time of the photo on the camera.

My plan is to use this to copy over photos that are between a date range.

Within the loop:  For Each itm In d.Items

I'm accessing each photo. It is then copied to the PC.

I've tried to use something such as: d.Items(5).Properties.Item("Item Time Stamp").Value
but am getting an error (Wrong # of arguments).

am reposting bulk of code below.


Option Explicit

Dim objWia As WIA.CommonDialog

Private Sub Form_Load()
Dim d As Device
Dim itm As Item
Dim imgpic As ImageFile
Dim lCounter As Long
Dim colRemove As Collection
Dim bDeleteAfterDownload As Boolean


    'instead of this, do a nice check for a checkbox
    bDeleteAfterDownload = True
    

    'used for me.print
    'if autoredraw = false, and you go to the vb debugging session, and restore your
    'app, the text is vanished!
    Me.AutoRedraw = True
    'create a ref to the wia commondialog.
    Set objWia = New WIA.CommonDialog
    'this makes sure a camera is selected, and no scanner.
    'the true part ALWAYS displays the dialog (normally omitted if only one dev is found)
    Set d = objWia.ShowSelectDevice(CameraDeviceType, True)
    
    
    'for this example, the files are downloaded every time to the
    'directory "downloaded images" in the project dir
    'you could check wether the image exists, before downloading it
    'so only the files that don't exist locally are transferred
    
    If Dir(App.Path & "\downloaded images\", vbDirectory) = "" Then
        'dir doesnt exist, create it
        MkDir App.Path & "\downloaded images\"
    Else
        'make sure the dir is empty!
        Dim tmpPath As String
        
                
        tmpPath = Dir(App.Path & "\downloaded images\", vbNormal + vbReadOnly)
        While Len(tmpPath) > 0
            Kill App.Path & "\downloaded images\" & tmpPath
            tmpPath = Dir()
        Wend
    End If
    
    
    Me.Show
    lCounter = 0
    Me.Caption = "Examining file " & lCounter & " of " & d.Items.Count & " please wait..."
    'loop trough all (root) items in the camera device
    For Each itm In d.Items
        Dim f As Properties
        Set f = itm.Properties
        Dim str As String
        
        'optional, display progress bar here
        'the total amount of pictures is stored in d.items.count
        lCounter = lCounter + 1
        Me.Caption = "Examining file " & lCounter & " of " & d.Items.Count & " please wait..."
        'give vb time to process its messages (else the app appears as not responding)
        DoEvents
        
        'is the item a file? (could also be a dir or so)
        If (f.Item("Item Flags") And ImageItemFlag) = ImageItemFlag Then
            'for reference:
            
            'f.Item("Full Item Name")       -> "0002\Root\IMG_1141"
            'f.Item("Item Name")            -> "IMG_1141"
            'f.Item("Filename extension")   -> "JPG"
            
            
            
            'check if the file exist locally (create your own function!)
            'If f.Item("Item Name") <> "nameoflocalfile" Then
            If bDeleteAfterDownload = True Then
                colRemove.Add itm.ItemID
            End If
            
            
                        
                'download the file to a temp buffer
                Set imgpic = itm.Transfer
                'store the file name and extension and app.path in a string,
                'so you can use it to perform more operations on it
                str = App.Path & "\downloaded images\" & f.Item("Item Name") & "." & imgpic.FileExtension
                
                'save the file (default format is used, bmp stays bmp, jpg stays jpg
                'this is why we switched to version 2.0 of the lib!
                imgpic.SaveFile str
                
                'you can process the image further here, it is now stored on your pc!
                '(add it to a list, to an picturebox, or whatever!)
                
            'End If
        End If
    Next
    
    If bDeleteAfterDownload = True Then
    Dim n As Long, i As Long
        For n = colRemove.Count - 1 To 0 Step -1
            For i = 1 To d.Items.Count
            If d.Items(i).ItemID = colRemove.Item(i) Then
                'Some Cameras don't support deleting pictures
                On Error Resume Next
                d.Items.Remove i
                If Err.Number <> 0 Then
                    MsgBox Err.Description
                    Err.Clear
                End If
                On Error GoTo 0
                Exit For
            End If
         Next
            
        Next
    End If
    
    
    Me.Caption = "finished, thanks for waiting!"
End Sub

Open in new window

0
Comment
Question by:scbdpm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:scbdpm
ID: 35058010
any suggestions on this WIA question?
Would reconsider code re-write if necessary.
0
 
LVL 2

Accepted Solution

by:
dlmichener earned 500 total points
ID: 35160046
I found that the date of the image is stored in a WIA.Vector object.  

The following code worked with my Canon PowerShot.  I'm not sure if the property names would be different or not.

Private Sub Command1_Click()
Dim objWia As WIA.CommonDialog, d As Device, i As Integer, j As Integer
Dim v As Vector, Name As String, Ext As String, PhotoDate As Date
   Set objWia = New WIA.CommonDialog
   Set d = objWia.ShowSelectDevice(WIA.CameraDeviceType, True)
   
   For i = 1 To d.Items.Count
      Name = d.Items(i).Properties("Item Name").Value
      Ext = d.Items(i).Properties("Filename extension").Value
      Set v = d.Items(i).Properties("Item Time Stamp").Value
      PhotoDate = v.Date
      Debug.Print "Photo Number " & Format(i, "##0") & "  Name: " & Name & "." & Ext & "  Date taken: " & PhotoDate
   Next i
End Sub

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35452408
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:scbdpm
ID: 35453705
I did finally have a chance to reviewt his code and it worked as I had requested.

thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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