Welcome to MSDN Blogs Sign in | Join | Help

Timed Camera Capture

Jason Langrage asked if it’s possible to automatically capture an image from the camera of a WM 5.0 Smartphone every 30 mins, and then to upload to a web service.

WM5.0 has three new ways of working with the camera, but unfortunately the two mechanisms easily accessible from managed code both require user input in order to capture an image.

The first new api is CameraCaptureDialog that allows an application to invoke the camera view so the user can capture stills, video or video and audio files to a store location on the device.

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

The second api is SelectPictureDialog and is a step further away from the camera, providing a list of images found on the device and an option to invoke the camera to capture another.

SelectPictureDialog ssdn = new SelectPictureDialog();

ssdn.ShowDialog();

pictureBox1.Image = new Bitmap(ssdn.FileName);

Both of these are useful, but can’t be used to automatically drive camera capture. The third new technique for working with the camera is through DirectShow. This is a fairly complex set of COM objects taken from the desktop equivalent and reduced to fit the device. It provides modular structure for processing video and audio data both for capture and for display. For full documentation of DirectShow on the desktop take a look here. For more specific info on DirectShow for Windows CE 5.0 take a look here.

There is a sample native app in the SDK called CameraCapture that shows how to use DShow to build a filter graph that takes the camera input, encodes it as a WMV and stores a video file. It also has a still image graph that stores a single still image as a file. It’s possible with CF 2.0 to turn the whole sample into managed code, but I couldn’t be bothered so I just converted the CameraCapture into a DLL, stripped the video bits to leave just the still image processing. Then a simple managed app with a timer fires the request every 30 seconds and uploads to a web service using Base64 encoding. Pretty straight forward really.

Anyway, if you want the code then its here:

TimedCamera.ZIP        - device camera code.

ImageUpload.zip          - web server code.

Extract the web site to your inetpub\wwwroot, right click on ImageUpload select Sharing and Security, then select the web tab and enable sharing with the default settings. Next build and run the TimedCapture code on your device. The standard code disclaimer applies.

I guess the next step is to use a socket to stream camera video from device to a desktop…

 

Marcus

 

Published Friday, March 03, 2006 1:57 PM by marcpe

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Un po' di codice managed per gestire la webcam

Friday, March 03, 2006 11:27 AM by Technology Experience

# re: Timed Camera Capture

I don't think anyone would want a new picture of the inside of my pocket every 30 minutes :)
Monday, March 06, 2006 11:41 AM by Scott

# re: Timed Camera Capture

Scott,
I'm sure you are right :) But imagine a mounted Pocket PC or Smartphone used as a 'cheap' security device sending images to a web server. For example, if you are a student using a shared fridge, stick your device to the inside door and catch the thief steeling your milk. Could be a lot of fun!
Or use the device for time laps image capture on a construction site.

Marcus
Tuesday, March 07, 2006 4:35 AM by marcpe

# Das nie endende Chaos! » Blog Archive » Automatisches Aufnehmen von Bildern unter WM5

# The Mobile Minute 136

TGIF!
Software / Hardware

Sling Media has released SlingPlayer for Windows Mobile (via msmobiles.com) ...
Friday, March 24, 2006 2:34 PM by Nino.Mobile

# re: Timed Camera Capture

i only want to get the Image'date(Example: BMP's Data),i don't how to do. when i find the TimeCamera.zip,
i download TimedCamera.zip,and use the graphmanager.cpp as the capture still image's app and transfer as CE tool's CameraCapture.nls.

when i debug this CameraCapture.exe:
m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));

hr != S_OK.

i use the mobile of Dopoda 830 for Develop!

what is wrong?
Thanks in advance.
Monday, April 10, 2006 12:27 AM by Nlgavin

# re: Timed Camera Capture

Marcus:

I download the "TimedCamera.ZIP" and load into VS 2005, I got error message is "Error retrieving information from user database. Platform not found", I had install Mobile 5.0 PPC SDK and DirectX SDK (2006.2 version). so, do you know how can I do ?
Thank you..
Monday, April 10, 2006 3:03 AM by Roger

# re: Timed Camera Capture

i get the TimedCamera.ZIP.
why alwasy faile at "CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, 0, 0 ,0,0 ));"
when i debug the nls on Dopod 830(WinCe 5.0 Pocket PC).

i come from china,i am an exacting task to read the article in English.maybe i miss same important's explain.

thanks very much for all helps.
Monday, April 10, 2006 11:34 PM by Gavin.Chen

# re: Timed Camera Capture

Hi Marcus,

I am finding that some win mobile 5 devices just wont run the Directshow TimedCamera code. Have you found the support of  cameras under winmob5 not as  standardized as it was supposed to be?

On the devices that do run it, I am having a real fight setting the image size, can anyone point me the right direction :-)

Wednesday, April 12, 2006 12:15 PM by Jon

# re: Timed Camera Capture

Hi there!

This code is exactly what I have been trawling the web for!  I need to make an application that will stream images from a Windows Mobile 2005 PocketPC (HTC Universal) to a web service so that clients can then view the "latest" image.  The standard Camera dialog is not suitable to the user intervention it requires, and my C++ knowledge is practically none-existent, so this wrapper for it is ideal.

However, I have run into a problem with it.  I have got the code working fine on the device, but every time I get a response from the camera of "Error from capture" and am unable to identify why. (This is in the ResponseToMessage method, in the switch statement, at the line "case (int)DSHOW_MESSAGE.MESSAGE_ERROR:".

I was wondering if you had any ideas why this might be, or could point me in the right direction?

Cheers!
Wednesday, April 26, 2006 11:21 AM by Simon

# re: Timed Camera Capture in native codes

I download .zip file. Successully compile CameraCaptureDLL.dll

Now I want to use it in my native code application. I tried:

=======================================
typedef BOOL (*fnInitializeGraph)(HWND hwnd);
typedef BOOL (*fnCaptureStill)(TCHAR szfile[MAX_PATH]);

BOOL CamCap()
{
INSTANCE hCam = LoadLibrary(TEXT("CameraCaptureDLL.dll"));
fnInitializeGraph funcInitializeGraph = NULL;
fnCaptureStill funcCaptureStill = NULL;

funcInitializeGraph = (fnInitializeGraph)GetProcAddress(hCam, TEXT("InitializeGraph"));

if (funcInitializeGraph)
{
    funcInitializeGraph(hWnd);
}
...
=======================================

the last function hungs up my application

what did I made worng?

Monday, May 08, 2006 4:54 AM by JG

# re: Timed Camera Capture

when I run the TimedCamera i get an error saying:

System.MissingMethodException was unhandled
 Message="Can't find PInvoke DLL 'CameraCaptureDLL.DLL'."
 StackTrace:
   at TimedCamera.TimedCaptureForm.Form1_Load()
   at System.Windows.Forms.Form.OnLoad()
   at System.Windows.Forms.Form._SetVisibleNotify()
   at System.Windows.Forms.Control.set_Visible()
   at System.Windows.Forms.Application.Run()
   at TimedCamera.Program.Main()

what am I doing wrong?

thanks!

lucasjordan AT gmail DOT com
Friday, May 12, 2006 2:03 PM by Lucas Jordan

# re: Timed Camera Capture

the code runs fine but no images.  put a breakpoint just after it captures the image but the image file does not exist.  dont really know how to stop the code at graphmanager.cpp so could not know what is going on.
Saturday, May 20, 2006 2:37 PM by acs

# re: Timed Camera Capture

Hi!

Has anyone tried to use it on i-mate SP5 smartphone. The error is "Error from capture" for me too, I think is has something with the hardcoded cameraGuid. :(. How can I find out the real guid?
Monday, May 22, 2006 8:47 AM by Roby

# re: Timed Camera Capture

BUG BUG
there is a cut paste error in my code. Sorry!
Just before I posted this I was tidying up the code to take out video capture and I remove one line that adds the filter graph for encoding.
I have dropped an updated ZIP over at the same link.

Marcus
Tuesday, May 23, 2006 6:32 AM by marcpe

# re: Timed Camera Capture

Marcus

Thanks for this code sample.  I tried it out on my new Cingular 8125, and it works like a charm.  However, I have only one problem:  the still images it takes are always 160 wide X 120 pixels high, and I can't seem to find any way in your code to set the image size.  

The phone has a 1.3 megapixel camera, and when I use the built-in picture taking program, 160X120 is the smallest size available, with a couple other bigger sizes including 1240 X 760 or something high resolution like that.

Do you know of any way to set this picture size?  Thanks.

Tuesday, October 31, 2006 12:14 AM by Kenneth Adams

# re: Timed Camera Capture

Hello

Do you have an example of performing real-time video analysis, using an i-mate camera ?

Thanks

Oren

Monday, December 04, 2006 1:23 AM by Oren

# re: Timed Camera Capture

hi,

I  have been having the same problem when trying to load the project file into VS 2005. I get the following messages:

'Error retrieving information from user datastore - Platform not found'

'The project could not be opened because it refers to a device platform that does not exist in your datastore'

The thing that worries me most is the fact that I have installed VS2005, windows ce 5.0, NET Framework etc, tried to rename/delete folder CoreCon/1.0 but still get the same error. Has someone any ideas? Many thanks.

Wednesday, December 20, 2006 9:45 AM by tzim

# re: Timed Camera Capture

I've been compiling CameraCaptureDLL.DLL with windows mobile 5 device platform successfully but when i add it into my windows mobile 5 smart device application reference, it will not be able to add and show message like this : A reference to CameraCapture.DLL could not be added. When I change DllImport into correct path of CameraCaptureDLL.DLL (Or when I copy file CameraCaptureDLL.DLL to c:\windows\system32 without changing the DllImport syntax),it will return message like this : MissingMethodException Can't find PInvoke DLL 'C:/CameraCaptureDLL.DLL'. I'm using ETEN Windows Mobile 5 Pocket PC. So how can i try your code ????? i need your help... thanks before email me at : cipinkman@cs.its.ac.id

Saturday, January 20, 2007 11:47 AM by aries firdiansyah

# re: Timed Camera Capture

You should install the Mobile 5 SmartPhone SDK

Wednesday, February 07, 2007 6:24 PM by Yosef

# re: Timed Camera Capture

Does anyone know how to take the video stream and display it in a mobile 5 application usng a media control to create a video preview form? Any links that would be useful as well. Thanks

Thursday, February 08, 2007 8:26 AM by Yosef

# re: Timed Camera Capture

Hi,

I am using the modified DirectShow Camera Capture sample for capturing the Video from my Win Mobile device. Now my problem is that I want to capture it direct-to-disk using directshow (so that the user can see real-time increase in size of the captured file and should also be abel to preview the file midway in between (using the local media player), while recording is still going on).

I could easily capture the video from the win mobile camera, and also the associated Audio. But it gets written to an asf file in the specified location, only after I manually stop the capturing by click of the Stop button on my custom interface. My need is that the captured audio and video keeps on getting written to the asf file continously as i capture, without depending on user input to stop the recording. This means that on start of the camera capture, a file should be instantaneously created in the specified location, and captured video/audio keeps on getting written frame-per-frame to this file and the file should keep on growing in size with the progress in capturing.

Please let me know how to do that, since I could not find anything on the same.

Please mail me if you got any solution on this at arjun.bahree@gmail.com

Thanks in Advance

Friday, March 23, 2007 3:28 PM by Arjun

# re: Timed Camera Capture

I wonder how to modify the upload portion, so the images can be uploaded using a standard web server via POST method.  I haven't found an API that does this, even though it's possible to construct a data stream resembling a POST action.

Friday, April 27, 2007 8:33 PM by doubletree

# re: Timed Camera Capture

Hi, thnx for this code! It comes really handy. I only can't find where to change the resolution. Do you (or anybody else)know where to do this.

Grtz and thnx again!!

Saturday, May 26, 2007 7:18 AM by Annihil8

# re: Timed Camera Capture

Hi Marcus,

This is a really useful bit of code, shame they couldn't put this into the managed API. Could you give me a pointer as to how I can get it to capture higher res? Do I need to create a custom filter?

Friday, June 15, 2007 4:09 PM by Thom Shannon

# re: Timed Camera Capture

do you have c# code please?thank you

Thursday, June 21, 2007 11:18 PM by china

# Timed Camera Capture - Update

Regards the Timed Camera Capture sample I posted last month, lots of you came across a bug in my code

Tuesday, July 03, 2007 2:15 AM by Marcus Perryman's WebLog

# re: Timed Camera Capture

Hello,

Many of you ask how to change the resolution of the image taken. I think following line of code should do it for you:

camera.Resolution = New Size(640, 480)

where camera is an object of class CameraCaptureDialog.

Cheers

Tuesday, July 03, 2007 12:31 PM by Nasir

# re: Timed Camera Capture

Hi

I didn't belive it helps - nevertheless I tried ;)

Code like this:

camera.Resolution = new Size(640, 480);

Doesn't help me with changeing the resolution!

Any other Ideas?

BR

Daniel

Monday, September 03, 2007 4:24 PM by Daniel

# re: Timed Camera Capture

when I run the TimedCamera i get an error saying:

System.MissingMethodException was unhandled

Message="Can't find PInvoke DLL 'CameraCaptureDLL.DLL'."

StackTrace:

  at TimedCamera.TimedCaptureForm.Form1_Load()

  at System.Windows.Forms.Form.OnLoad()

  at System.Windows.Forms.Form._SetVisibleNotify()

  at System.Windows.Forms.Control.set_Visible()

  at System.Windows.Forms.Application.Run()

  at TimedCamera.Program.Main()

what am I doing wrong?

thanks!

Wednesday, September 12, 2007 8:22 AM by ibrahim

# re: Timed Camera Capture

Hi!

How To change Camera Rotation and Resolution

Please Help...

Friday, September 14, 2007 3:30 AM by ibrahim

# re: Timed Camera Capture

Hello,

I have the same problem as you all. I can't change the resolution for the pictures (only 160x120)

Did any of you found a solution ?

Saturday, September 22, 2007 4:31 PM by Mayor

# re: Timed Camera Capture

I got the following error when i try to deploy the application:-

Unable to start program '%CSIDL_PROGRAM_FILES%\TimedCamera\TimedCamera.exe'. The system cannot find the file specified.

Can anybody please help me out?? It's very urgent please!!!

Tuesday, September 25, 2007 8:02 AM by Amit Verma

# re: Timed Camera Capture

Hi I want to change the camera zoom value but I've had some troubles. I must use IACameraControl::Set interface Can you help me with this please?

Wednesday, October 10, 2007 4:56 PM by Omar

# re: Timed Camera Capture

I don't have ImageUpload web site. Is anyone willing to share his URL with me?

Thanks a lot.

MSN/Email: hendryyang@hotmail.com

Thursday, October 11, 2007 5:22 AM by greathendry

# re: Timed Camera Capture

I would like to change the resolution to 640 by 480. Can anybody post a code sample of how to change this.

Wednesday, October 17, 2007 1:46 AM by Jami

# re: Timed Camera Capture

Anyone found a resolution for this error yet:

Can't find PInvoke DLL 'CameraCaptureDLL.dll'

Thanks,

nb

Wednesday, November 14, 2007 3:14 PM by Noble D. Bell

# re: Timed Camera Capture

Resolution for "Can't find PInvoke DLL 'CameraCaptureDLL.dll"

It is during deployment of the app to your phone/pda that this file is not getting copied.  That's why when the app executes, it can't find the file -- it was never there to begin with.

A solution is to add this file into your VS.net 2005 project.  in Solution explorer, right-click the project and choose Add>Existing Files, then select the CameraCaptureDLL.dll.

Once the file is added, check the properties.  It should say that the file is considered as 'Content'.  Set the option to Copy to Output Directory All the Time.

Rebuild and re-deploy.  The error should now disappear.

Wednesday, December 05, 2007 1:23 AM by Herman

# Windows Mobile Development » Blog Archive » Capturing photos without using the CameraCaptureDialog class

# re: Timed Camera Capture

I have used your program to record video and still image capture but when added the code for preview its getting hanged. Do u know whats the reason behind it. I am using HP iPaq Mobile device with windows mobile ver 5.0.

I am using a panel to show the preview in C# and passing this handle to dll function private static extern bool InitializeGraph(IntPtr hWnd, IntPtr hwndPanel);

Wednesday, March 19, 2008 4:03 AM by Anil Sambasivan

# re: Timed Camera Capture

Hello

I try to captre images from Pocket PC's camera, about 10 images/s. the CameraCaptureDialog()

doesn't work as I need. so can you tell me how to do?

thanks

Wednesday, April 02, 2008 8:00 PM by kim

# re: Timed Camera Capture

for you task about Can't find PInvoke DLL 'CameraCaptureDLL.dll'

you have to put the dll file in the same directory with your compiled programm in the device you use.

I hope it will be helpful for you

Wednesday, April 02, 2008 8:12 PM by archer

# re: Timed Camera Capture

For those asking about image size, goto MSDN and look-up the COM API's used in "CGrapManager::CaptureStillImageInternal()" and fix it yourself...

Friday, June 06, 2008 10:46 AM by peopleNeedToUseMSDN

# re: Timed Camera Capture

Hi Marcus,

Really great work! I was able to make run this on HTC mobile phones. Can you just give a clue on how to make the camera available to users in the code.

Regards

Sasi

Wednesday, June 11, 2008 6:37 AM by Sasikumar

# re: Timed Camera Capture

Works great on CE5 HP device.

Anybody run this on CE6?  All I get is a black screen, tried 2 different device makes.  

Regards,

Seán.

Wednesday, July 02, 2008 9:07 AM by Sean

# re: Timed Camera Capture

It works fine for 1 sec but throws error for less than one second capturing. Do some fix is required to capture 1 / 2image per second.

Monday, July 07, 2008 12:37 PM by Sasikumar

# Camera Flash

I`m looking for code using camera flash because I`m trying to do flash light from phone. I have seen your code but is hard for me. Could you give some url to material about programing phone camera(exacly i need turning on and off the camera flash)?

Monday, July 28, 2008 8:40 PM by karol

# re: Timed Camera Capture

Folks,

I am using Visual C# 2008 and windows mobile 6 and I wander if anybody has used it under the same system.

Tuesday, September 16, 2008 12:32 PM by Mohammad rahimi

# re: Timed Camera Capture

Did anybody figure out how to set the resolution of the camera using IAMCameraControl. I can not find the right parameters for the set function

Thursday, September 18, 2008 2:00 PM by Mohammad rahimi

# re: Timed Camera Capture

i use these code in two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

i don't know why it doesn't work and appear errors ?

Saturday, September 20, 2008 9:31 AM by S.Majid

# re: Timed Camera Capture

i use these code in C# with two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

i don't know why it doesn't work and appear errors ?

anyone could capture image with this method ?

Thanks in advance

Saturday, September 20, 2008 9:32 AM by S.Majid

# Camera Capture

i use these code in C# with two camera (HP Photo Samart SD camera & FlyCam CF 1.3M) but it didn't work

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

i don't know why it doesn't work and appear errors ?

anyone could capture image with this method ?

Thanks in advance

Saturday, September 20, 2008 9:35 AM by S.Majid

# Israr Khans blogg » Blog Archive » links for 2008-09-20

# Time Camera Capture

I've always wanted my phone to take a picture with the camera a few seconds after I initiate a phone

Sunday, October 26, 2008 8:20 PM by Windows Mobile Development

# re: Timed Camera Capture

hi,

i've project on pocket pc

my problem is:

how can i deal with camera directly so that i can take pictures and save them while capturing a video . (snapshots)

thanx anyway

kind regards

Monday, November 17, 2008 6:16 AM by salam

# re: Timed Camera Capture

Can't download any of the zip files. Are they still available???

Wednesday, December 24, 2008 4:33 PM by IraqiGeek

# re: Timed Camera Capture

sorry but you're wrong, you can use the camera capture dialog to take pictures automatically if you use it with another thread wich press the take picture key for you. it's really easy to made.

Tuesday, January 13, 2009 10:32 AM by Carlos

# DirectShow | keyongtech

Sunday, January 18, 2009 12:16 PM by DirectShow | keyongtech

# Auto image capture from camera? | keyongtech

Thursday, January 22, 2009 2:23 AM by Auto image capture from camera? | keyongtech

# re: Timed Camera Capture

Guys!

I used this code:

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.ShowDialog();

pictureBox1.Image = new Bitmap(ccd.FileName);

But it´s needed to add references in project.

- Microsoft.WindowsMobile

- Microsoft.WindowsMobile.Forms.

Without this references the class CameraCaptureDialog doesn´t works corretly.

Friday, January 23, 2009 8:01 AM by Andre Putz

# Downloads not working...

The downloads are timing out. Any mirrors for them?

Thanks

Sunday, March 01, 2009 3:20 PM by TrickiDicki

# re: Timed Camera Capture

Hi Everbody,

i have the same dll not found problem. i could not open CameraCaptureDLL project in VS2005. Can you help me to get CameraCaptureDLL.dll file please?

Friday, March 13, 2009 11:17 AM by Resul Özdemir

# re: Timed Camera Capture

Hi, I want CameraCaptureDialog should not go in Standby Mode after 30 seconds as it is going.

I want to extend this time.

Is it possible ?

Wednesday, March 18, 2009 2:32 AM by Aqil

# Resolution

Hi Marcus,

Can you help about the image resolution?

Thursday, March 19, 2009 10:37 AM by resooul

# re: Timed Camera Capture

Hmm, if I'm not mistaken you could use this code to create a custom camera dialog?

Thursday, June 11, 2009 7:16 AM by junk

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker