I use WIALib to access my webcam. The code I'm developing is pretty simple: when you click the button, the webcam is captured and then displayed in the image window.
I can already take pictures using my webcam, but it is not yet fully automated. The only way to find pictures taken with a webcam is as follows:
wiaPics = wiaRoot.GetItemsFromUI( WiaFlag.SingleImage, WiaIntent.ImageTypeColor ) as CollectionClass;
But this asks the user to select an image. And I always need the last photo. Therefore, I try:
string imageFileName = Path.GetTempFileName(); // create temporary file for image wiaItem = wiaRoot.TakePicture(); // take a picture Cursor.Current = Cursors.WaitCursor; // could take some time this.Refresh(); wiaItem.Transfer(imageFileName, false); // transfer picture to our temporary file pictureBox1.Image = Image.FromFile(imageFileName); // create Image instance from file Marshal.ReleaseComObject(wiaItem);
But the TakePicture () method returns null, so I can not pass the image. The strangest thing is that the picture was really made after the TakePicture () method was called, because if I manually move around the webcam, there will be an image! I just don't understand why it is not returning a value.
To summarize, I need either one of two things: 1. Get TakePicture () to work, returning a value that I can use. 2. The list of webcam photos is accessed automatically, so I can get the last image taken.
Best regards and thanks for the help, Michael.
source share