Sunday, January 14, 2001 ..:: Home ::.. Register  Login
   TechTidBits (Blog)  

Why can’t the WP7 use the LED for the Flashlight? (yet!)

Oct 25

Written by:
Tuesday, October 25, 2011 9:12 PM  RssIcon

ScreenCapOfLEDFlashlightThere are a lot of flashlight apps out there for all of the smartphones.  In fact, IMHO, it’s the new Hello World application!  But why is it SO hard to use the LED on the WP7?  Read on for why.

imageLast year (one year today actually), I was lucky enough to be able to release miFlashlight for the newly released Windows Phone 7!  At that time, the ONLY way to create anything that remotely resembled a flashlight/torch, was to set the background to white.  Fancy eh? haha But it did work. 

My Android friends laughed at me though cause they could use their LED flash on their cameras.  I knew the Android platform was open, but THAT open to have API access to the Flash?  Man, THAT was cool.  Well, this week I found out what in fact they were/are doing, and it’s not really THAT impressive.  Read on for “the trick.”

Executive Summary

The quick version of the story is, you set the flash on, take a picture, throw the picture away (LED flash fires), rinse and repeat!  Ya… that’s it.  Simple, effective, and really quite nifty!

Dev Summary

The meat here is you have to start taking pictures.  There are quite a few blogs out there showing you how to take pictures, but I found two hiccups that maybe you found to, but in case you didn’t, here’s what I found.

imageFirst off, you have to add the ID_CAP_CAMERA line to the WMAppManifest.xml file.  Ironically, without it, nothing happens with the camera, no exceptions, no errors, NOTHING.  Kind of like how my Habs are doing this year, NOTHING (so far that is, DOH!).  Anyways, you need this in your WMAppManifest.xml.

<Capability Name="ID_CAP_CAMERA"/>

Next, you HAVE to have a VideoBrush object linked up to the CameraPhoto object in order for the camera to correctly initialize.

    <VideoBrush x:Name="viewfinderBrush"/>

If you DON’T have the VideoBrush in XAML and associated to your CameraPhoto object, then your Initialized event NEVER fires, and you’ll NEVER take any pictures.  Don’t believe me?  Try it out for yourself, hey, I didn’t believe it myself, but it’s true.  Without a view finder, you can’t snap any pics.

camera.Initialized += new EventHandler<CameraOperationCompletedEventArgs>( camera_Initialized );
camera.CaptureStarted += new EventHandler( camera_CaptureStarted );
camera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>( camera_AutoFocusCompleted );
camera.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>( camera_CaptureCompleted );
camera.CaptureImageAvailable += new EventHandler<ContentReadyEventArgs>( camera_CaptureImageAvailable );

viewfinderBrush.SetSource( camera );

Ok, after this point, you .CaptureImage() then just do nothing with the picture in the CaptureCompleted event.  No worries right?  So then what the heck is wrong with using the LED flash??????????????!!!!!!!!!!!?!?!!?!

Here’s the problem.  When you take a picture, it takes a couple seconds (litterally a couple of seconds, ya, seconds, not millieseconds) to process the picture, pass it off to your code by firing the CaptureCompleted event.  HHMMMM  At first I thought if I dialed down the 1920X2560 resolution of the picture taken (using AvailableResolutions enum you can see the smallest resolution is 480X640), it STILL takes a few seconds to process the picture.  And if you’re too fast on the draw, and try to short circuit things by calling the CaptureImage() before the previous picture is finished……weeeeeell, think again… ya InvalidOperationException.



The thing that gets me is, if you try to take a video with the flash on….IT WORKS!!!!!  So I KNOW if can be done.  It’s just available in the API to use yet….YET!!!!!!!!!!

Now, what’s the harm in the current implementation.  Well, with it, you’ll notice you get quite a BRIGHT light via the LED flash, you can clearly see our cat George in a pitch black hallway.  The video I took was completely black when I tried to shine miFlashlight with the white background on George, not very good IMHO.


Firefly FlashlightNow, others have tried to release LED flashlights claiming to work, but they’re really just doing the same tricks as above.  The results is a flashing light, strobe light if you will.   Try relying on THAT when you’re walking down a dark stairway.  Not me, thanks.

SO!  I hope this helps to shine a bit of light onto why we WP7 devs (still) can’t get the LED to “FLASH” for us…yet!!!!!!!!!!!  I DO hope it’ll come in the next API release…or at least in the video class structure.  Until then, it’s time to grab a coffee and get coding!




ArcGIS Resource Center: Thread: picture attachment – WP7 camera API

Location: Blogs Parent Separator TechTidBits

5 comment(s) so far...


Re: Why can’t the WP7 use the LED for the Flashlight? (yet!)

if (string.Equals(btn_Run.Content, "start"))

cam.FlashMode = FlashMode.On;
btn_Run.Content = "end";
cam.FlashMode = FlashMode.Off;
btn_Run.Content = "start";

maybe ur right!MS still not provide the API for us.It doesn't work,2.:)

By Fox on   Thursday, December 01, 2011 7:00 AM

Re: Why can’t the WP7 use the LED for the Flashlight? (yet!)

Em, that app you linked to in this post turns on the LED flash on my phone with no flicker.

By Robert Walter on   Monday, December 05, 2011 3:26 PM

Re: Why can’t the WP7 use the LED for the Flashlight? (yet!)

Hi Robert, thank you for leaving me a blog comment. Can I ask, what phone do you have? Do you have a Focus or something else? I have a Focus. I tried a few, and they all do the same thing on my phone (flash not stead), so I would love to know what works. Are you doing any WP7 dev at all? Thanks again for leaving a comment and have a good week!

By Peter Henry on   Monday, December 05, 2011 3:45 PM

Re: Why can’t the WP7 use the LED for the Flashlight? (yet!)

Henry, try Firefly Flashlight 3.2 (you link to this), Flashlight 7 4.4 or Flashlight-X 2.0. All of them work great on my Samsung Focus.

By Robert Walter on   Tuesday, December 06, 2011 10:40 PM

Re: Why can’t the WP7 use the LED for the Flashlight? (yet!)

Hi Robert, thanks for the heads up. What I'm REALLY interested in figuring out though is, how the heck did they GET the LED TO STAY ON?!?!?!?!?!? DOH! That's what I can't figure out myself and it's driving me nuts! Do you know? Thanks for leaving me a comment and as soon as I get my Focus back (long story, check out my twitter account PeterHenry9999 for the long story) I'll check these out! Thanks for leaving a comment and your suggested apps! (ps my first name is Peter, I get the Henry sometimes, no worries haha). Have a good week!

By Peter Henry on   Tuesday, December 06, 2011 11:01 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Add Comment   Cancel 
Copyright 1999-2012 by   Terms Of Use  Privacy Statement