Windows Phone 7 – 相机闪存应用程序无法运行

在尝试按照这里的说明 – http://msdn.microsoft.com/en-us/library/hh202949.aspx我编写了一个非常简单的WP7应用程序来打开相机闪光灯。 一切似乎都有效,除了……闪光灯没有激活。

我的手机是三星SGH-I917(最新的操作系统更新),我使用的是WP7 SDK 7.1,我已经检查过我相机的闪光灯确实可以正常工作。 我还检查了以确保以下内容位于WMAppManifest.xml文件中。

 

您在下面的代码中看到的MessageBox用途表示相机对象已正确初始化,支持FlashMode.On并且已设置FlashMode.On 。 然而……实际上没有闪光灯开启。 我错过了什么?

这是代码:

 public partial class MainPage : PhoneApplicationPage { PhotoCamera cam; public MainPage() { InitializeComponent(); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { cam = new PhotoCamera(CameraType.Primary); cam.Initialized += new EventHandler(cam_Initialized); cam.CaptureCompleted += new EventHandler(cam_CaptureCompleted); cam.CaptureImageAvailable += new EventHandler(cam_CaptureImageAvailable); cam.CaptureThumbnailAvailable += new EventHandler(cam_CaptureThumbnailAvailable); viewfinderBrush.SetSource(cam); } void cam_CaptureThumbnailAvailable(object sender, ContentReadyEventArgs e) { return; } void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e) { return; } void cam_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e) { return; } protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { if (cam != null) { cam.Dispose(); cam.Initialized -= cam_Initialized; cam.CaptureCompleted -= cam_CaptureCompleted; cam.CaptureImageAvailable -= cam_CaptureImageAvailable; cam.CaptureThumbnailAvailable -= cam_CaptureThumbnailAvailable; } } void cam_Initialized(object sender, CameraOperationCompletedEventArgs e) { this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show("Cam Init, FlashMode.On Supported?: " + cam.IsFlashModeSupported(FlashMode.On).ToString()); }); return; } private void Button_Click(object sender, RoutedEventArgs e) { if(cam.FlashMode == FlashMode.On) cam.FlashMode = FlashMode.Off; else cam.FlashMode = FlashMode.On; this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show(cam.FlashMode.ToString()); }); } } 

这是XAML:

                 

 cam.FlashMode = FlashMode.On; 

仅表示捕获图像时闪光灯将被激活。

这是通过做到的

 cam.CaptureImage(); 

编辑:如果你只想触发闪光灯,你可以调用cam.Focus();