473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WIA image capture in Windows 7

tuxalot
200 100+
Using the code below to capture images in Access. On my form is an unbound OLE image and a single button. Clicking the button when a digital camera is connected via USB and turned on causes the camera to take a pic and show it in the OLE image frame.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGrabImg_Click()
  2.     'Take a picture from a webcam and store it in a temp file.
  3.     'By Justin Johnson Nov 26, 2007
  4.  
  5.     On Error GoTo Err_btnTakePicture_click
  6.  
  7.     Dim tempfile As String
  8.     Dim mydevice As WIA.Device
  9.     Dim item As WIA.item
  10.     Dim imfile As WIA.imagefile
  11.     Dim Commondialog1 As WIA.CommonDialog
  12.     Dim MyFilename As String
  13.  
  14.     MyFilename = "C:\Documents and Settings\" & Environ("Username") & "\Desktop\" & "WIAGrab" & ".jpg"
  15.  
  16.     'put the path and name for the location of your temp file here.
  17.     tempfile = ("" & MyFilename & "")
  18.  
  19.     'the next 4 lines deletes the old temp file if it exists
  20.     Set filesystemobject = CreateObject("Scripting.FileSystemObject")
  21.     If filesystemobject.FileExists(tempfile) Then
  22.         Kill (tempfile)
  23.     End If
  24.  
  25.     'the next two lines set up the configuration
  26.     Set Commondialog1 = New CommonDialog
  27.     Set mydevice = Commondialog1.ShowSelectDevice
  28.  
  29.     Set item = mydevice.ExecuteCommand(wiaCommandTakePicture)        'instructs the camera to take the picture
  30.  
  31.     Set imfile = item.Transfer        'transfers the picture from the camera
  32.  
  33.     'this line saves the picture to a specified file
  34.     imfile.SaveFile (tempfile)
  35.  
  36.     'this sets the picture on the form to show the new picture
  37.     Me.OLEUnbound1.Picture = (tempfile)
  38.  
  39.     'MsgBox "Picture taken"
  40.  
  41. Exit_btnTakePicture_click:
  42.     Set mydevice = Nothing
  43.     Set item = Nothing
  44.     Exit Sub
  45.  
  46. Err_btnTakePicture_click:
  47.     MsgBox Err.Description, vbOKOnly + vbCritical, "Error Taking Picture"
  48.     Resume Exit_btnTakePicture_click
  49.  
  50. End Sub
Works great in Windows XP but fails in W7 with an error stating: "object variable or with block variable not set". The camera does open up and flash so it appears to take the picture but no result in image frame.

Any ideas what is causing this to fail?

Thanks!
Jan 30 '12 #1
18 23715
sierra7
446 Expert 256MB
Hi
For this to work I presume you will have installed a device driver for your camera which will have included a '.dll' that installs Windows Image Acquisition services.

My presumption is that you will need a different driver for Windows 7

If you set a break point at the top of the code then step through it, you should be able to identify the line where the error ocurrs.

Running your code without any sort of WIA driver causes a 'User-defined type not defined' error at Line #7.

S7
Jan 30 '12 #2
NeoPa
32,556 Expert Mod 16PB
Tux:
but fails in W7 with an error stating: "object variable or with block variable not set".
I shouldn't be needing to tell you the basics like which line this occurs on Tux. You've also failed to include the procedure header line, which is often required to make sense of code - especially when the code posted is 50 lines. I won't delete the question as I'm sure you'll fill in the details, but please remember for future questions.
Jan 30 '12 #3
tuxalot
200 100+
Thanks Sierra - The camera when connected via usb I assume installs a universal driver, yes. It installed fine in XP and W7 with no interaction (Windows auto-installed drivers). It's a modest Nikon L22 point and click.

NeoPa - If I comment line 26 or 27, I get the error mentioned and the camera does not take the picture. Leaving 26 and 27 in, I get the error mentioned and the camera snaps a shot. Looking at the camera SD card I see the image gets stored there, so I suppose it's just not transferring. I have read more recently that WIA may have issues with W7. Can't seem to find much on this topic unfortunately.
Jan 31 '12 #4
NeoPa
32,556 Expert Mod 16PB
It sounds like you don't know how to determine which line the error occurred on. When the error is reported, which line is highlighted in yellow in the debugger when you select Debug?
Jan 31 '12 #5
tuxalot
200 100+
There is no debug option in the dialog box that is presented.
Jan 31 '12 #6
sierra7
446 Expert 256MB
Hi again,
If you say the code works in XP, I can't think there is anything wrong with the code per se, which I why I suspect a driver problem.

I've Googled 'windows 7 driver for Nikon L22' and found the a number of sites purporting to supply updated drivers. Note that there are 32 and 64 bit versions of software that have minor differences (What version of Access are you using? There are some issues with Service Pack 1 in the 64 bit version of Access 2010. Not certain what because I'm not affected by using 32 bit on 64 bit Win7, but I'll check it out)

As you seem to be able to communicate to the camera but the system fails when processing the returned image to the OLE image frame, i still favour a driver update.
S7

PS. I've checked out the issue I mentioned above. It appears to be associated with running Wizards and generally not working. Here's a link "Access 2010 - Wizards not working after installing SP1"
Jan 31 '12 #7
NeoPa
32,556 Expert Mod 16PB
Tux:
There is no debug option in the dialog box that is presented.
It sounds like you haven't set your system up correctly for debugging then. Ooooops. Debugging in VBA - 3) General Tips can help you with that.

You may find that much of your development will become easier after this point.

PS. This doesn't argue with S7's comments and advice. They may be absolutely correct (I expect they are). However, it's still always important to include such information as the line number where the error occured as the basic details of a question if posting code that crashes :-)
Jan 31 '12 #8
tuxalot
200 100+
Sierra - I am running 32 bit Access 2010. Also note on the MS site they say the L22 is compatible with W7 and no further drivers are necessary. I too looked at the many sites mentioning updated driver files, but those that I found are just feeder sites to get one to download non-related software which searches for updated drivers on your PC.

NeoPa - thanks for the tip :)

My code is failing at Line 31.
Feb 1 '12 #9
NeoPa
32,556 Expert Mod 16PB
Good for you Tux.

I'm afraid my comments were more as a moderator than as an expert as I have no experience with this device or driver. Having your code posted with the error message and line number included are always helpful though, and if it's helpful to any of us then it benefits you too, clearly.

Good luck with your problem.
Feb 1 '12 #10
tuxalot
200 100+
Thanks NeoPa. I appreciate all you do. The bashing I get from you from time to time is clearly deserved. I WILL get this. I am just a bit dense at times ;)
Feb 1 '12 #11
tuxalot
200 100+
I've established that the procedure above will activate a camera and save the pic to the SD card of the camera in XP and W7. I need code that can find the most recent saved file in a directory of my cameras' SD card (would be the current image), and save that path to an Access table. Seems doable, but the code below fails at line #13 (explanation follows):

Expand|Select|Wrap|Line Numbers
  1. Public Function GetMostRecentFile()
  2.     Dim FileSys As FileSystemObject
  3.     Dim objFile As File
  4.     Dim myFolder
  5.     Dim strFilename As String
  6.     Dim dteFile As Date
  7.  
  8.     'set path for files - change for your folder
  9.     Const myDir As String = "L22" '<<<fails here
  10.  
  11.     'set up filesys objects
  12.     Set FileSys = New FileSystemObject
  13.     Set myFolder = FileSys.GetFolder(myDir)
  14.  
  15.  
  16.     'loop through each file and get date last modified. If largest date then store Filename
  17.     dteFile = DateSerial(1900, 1, 1)
  18.     For Each objFile In myFolder.Files
  19.         If objFile.DateLastModified > dteFile Then
  20.             dteFile = objFile.DateLastModified
  21.             strFilename = objFile.Name
  22.         End If
  23.     Next objFile
  24.  
  25.     MsgBox strFilename
  26.  
  27.     Set FileSys = Nothing
  28.     Set myFolder = Nothing
  29.  
  30. End Function
I understand some cameras connect via USB using PTP (Picture Transfer Protocol) while others, especially the older and more high end cameras use MSC (Mass Storage Communication) or have the ability to choose the communication protocol. MSC devices are assigned a drive letter while PTP cameras are not. So that's a dead end unfortunately.

That said...

Is there a different way to transfer the most recent camera image captured? As mentioned, my code posted at #1 works fantastic in Windows XP, but not in W7.
Feb 1 '12 #12
sierra7
446 Expert 256MB
OK, I seem to have been on the wrong track here! I had assumed that the extra driver required to give you WIA functilonality was installed by the Nikon software.

Silly me; you seem to have downloaded the WIA Development kit from Microsoft. There are full instructions and example code included in the kit.

The required dll is WIAaut.dll for the WIA Automation layer. When I came to copy it from the kit I found there was one already installed (I'm using Win7 Ultimate. My version was 6.1.7600 the file from the kit is version 5.1.2600). Ive kept both but set a Reference in Access to the latest version. Although it was located in the System32 folder it was 'not on the list' and had to be browsed to.

I can't test out the code because although I have acquired a Nikon S4150 it does not seem to respond.(just yet!)

Refering back to your last post (find latest file) the code does work if a valid path (eg c:\L22) is defined at Line #9

However, when searching for a dll to control my camera I found that Nikon supply a fully functional application Camera Control Pro 2
It's far more comprehensive than I would write myself. I'm not sure what they will charge when the trial period expires!
S7.
Feb 6 '12 #13
tuxalot
200 100+
Correct S7, that is the WIA download.
Feb 6 '12 #14
sierra7
446 Expert 256MB
Hi
I'm stll looking into this for my own interest but making slow progress because of other matters.

I've abandoned Win7, for the moment because it would not recognise the camera, so nothing would work. I can confirm your findings that thing works much better in XP.

While still using XP I found that although I could see the camera in Windows Explorer I could not read from the memory card. However, there was a utility in the Nikon software which came with camera that seems to have switched it so the memory card can now be read, but it still does not respond in Access 2010.

In passing, the camera is not assigned a drive letter so cannot be addressed using the syntax you used. It seems that your "L22" may be a volume name and will have to be referred to differently using "\\.\Volumename(Unique Identifier).." type of syntax. This is new to me but I'll be more clear when I get it working.

I am able to take pictures in Access 2003 using your code (well, it did not like the OLEUnbound1 object and I had to convert it to an Image frame, and I had to add a Commondialog1 control to the form)

Interestingly, in Access2010 it is possible to add a WIA.DeviceManger control to a form but it is not possible to add a WIA.CommonDialog control from the ActiveX list on the ToolBar. It gives a message saying the dll is nor registered but when you run RegSvr32 wiaaut.dll, it responds it has registered successfully. I think this is the hub of the problem.

I'm adding some code that cycles through the properties of the camera. This allows you to see the Unique Identifiers by which the camera is known to the system, where-upon you may be able to access the memory card, maybe! This is from MSDN Shared Samples
Expand|Select|Wrap|Line Numbers
  1. Dim dev 'As Device
  2. Dim p 'As Property
  3. Dim s 'As String
  4. Dim i 'As Integer
  5.  
  6. Set dev = CommonDialog1.ShowSelectDevice
  7.  
  8. For Each p In dev.Properties
  9.     s = p.Name & "(" & p.PropertyID & ") = "
  10.     If p.IsVector Then
  11.         s = s & "[vector of data]"
  12.     Else
  13.         s = s & p.Value
  14.         If p.SubType <> UnspecifiedSubType Then       
  15.             If p.Value <> p.SubTypeDefault Then
  16.                 s = s & "(Default = " & p.SubTypeDefault & ")"
  17.             End If
  18.         End If
  19.     End If
  20.  
  21.     If p.IsReadOnly then
  22.         s= s & " [READ ONLY]"
  23.     else
  24.         Select Case p.SubType
  25.         Case FlagSubType
  26.             s = s & " [ valid flags include:"
  27.             For i = 1 To p.SubTypeValues.Count
  28.                 s = s & p.SubTypeValues(i)
  29.                 If i <> p.SubTypeValues.Count Then
  30.                     s = s & ", "
  31.                 End If
  32.             Next
  33.             s = s & " ]"
  34.         Case ListSubType
  35.             s = s & " [ valid values include:"
  36.             For i = 1 To p.SubTypeValues.Count
  37.                 s = s & p.SubTypeValues(i)
  38.                 If i <> p.SubTypeValues.Count Then
  39.                     s = s & ", "
  40.                 End If
  41.             Next
  42.             s = s & " ]"
  43.         Case RangeSubType
  44.             s = s & " [ valid values in the range from " & _
  45.                    p.SubTypeMin & " to " & p.SubTypeMax & _
  46.                    " in increments of " & p.SubTypeStep & " ]"
  47.         Case Else 'UnspecifiedSubType
  48.         End Select
  49.     End If
  50.  
  51.     MsgBox s
  52. Next
  53.  
  54.  
I just put the code under a command button and the information is displayed in a series of MessageBoxes.
S7
Feb 9 '12 #15
tuxalot
200 100+
Very nice S7. I am looking forward to seeing what you come up with - Your knowledge and understanding about how to get this done is far better than mine.
Feb 9 '12 #16
sierra7
446 Expert 256MB
This will be too long for a PS..
Obviously, you can read the mempory card if you extract it from the camera and insert it into a cardreader slot, as it's then assigned a drive letter.

I'm interested in developing this for astronomy, when it's too cold to go outside to the telescope! As the images are transferred to the pc OK I will just number them sequentially and store them locally (as well as on the memorycard), so finding any particular shot will just be a matter of browsing. There is a browser in the Development Kit which just has to be converted from VB To Access VBA.
S7
Feb 9 '12 #17
tuxalot
200 100+
I may just end up buying a camera with MSC functionality. But I would still like to see if my trusty Nikon L22 can work somehow. Have you had any time S7 to move forward on this? The stars outside are waiting ;)
Feb 24 '12 #18
There is an error in the original code above on line 37. It should read:
Me.OLEUnbound1.Picture = LoadPicture(tempfile)
Jun 25 '13 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
3
by: Catalin Lungu | last post by:
Hi, Can anybody help me to implement the following VB code in Python. Thanks in advance. Private Declare Function SendMessage Lib "user32.dll" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal...
4
by: | last post by:
Hi, What is the best way to capture images from a FireWire DCAM camera? Is there any support for the DCAM protocol anywhere for C# on Windows 2000? If I understand it right TWAIN = legacy and...
2
by: Paul Aspinall | last post by:
Hi I am trying to find some code, or reference docs, to assist in helping capture images from an image capture device (ie. webcam etc etc). I want to be able to compare successive images coming...
0
by: subirose | last post by:
Hi, For my web application I need to create an html input form form which I need to extract the entered data and also save the filled form as an image when the user submits the form. I have seen...
2
by: ghostrider | last post by:
Hi, I am working on an access app and need to capture still images from a monitor connected to medical equipment. The video out port on the monitor is connected to a video card in the computer...
4
by: ink | last post by:
Hi All, I am trying to build an image capture user control using DirectShow to be used in an existing C# application. It needs to have a view finder/ preview window and be able to take...
2
by: wingsganesh | last post by:
Hi Guys, I dont know how to send image in windows mobile 6. i captured image using CameraCaptureDialog class and displayed that image in picture box. but still, i need to send this image in one...
1
by: selvaraman | last post by:
I need to Open an Image via Windows Fax Viewer. I have tried with the following types of codes. But, None of them giving the answer. iOpenImageResult = ShellExecute(0&, "open", "mspview",...
4
by: sightless | last post by:
Hi all, Is it possible to capture Windows user login in Unix? We have a AIX Unix system that allows users to login (using a common login) and run scripts. At the end of the day, we cannot find out...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.