是否可以在WP7中打开相机的闪光灯?
答案 0 :(得分:13)
现在可以在Windows Phone OS 7.1 SDK中使用。
以下是MSDN文章的链接:Access Camera API on WP7
PhotoCamera cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
cam.FlashMode = FlashMode.On;
答案 1 :(得分:2)
这不能在当前的SDK中以编程方式完成。
用户可以通过手机独家控制此功能。
答案 2 :(得分:1)
嗨看看这个链接。 我认为你的问题有帮助
http://msdn.microsoft.com/en-us/library/hh202949%28v=vs.92%29.aspx
答案 3 :(得分:0)
1)在主页面XAML文件MainPage.xaml中,在名为ShutterButton的Button元素下面的StackPanel元素中添加以下代码。此代码是相机闪光灯的按钮。
<Button Name="FlashButton" Content="Fl:TBD" Click="changeFlash_Clicked" FontSize="26" FontWeight="ExtraBold" Height="75"/>
2)打开主页面的代码隐藏文件MainPage.xaml.cs,并在MainPage类构造函数上面添加以下变量声明:
//保持当前的闪光模式。
private string currentFlashMode;
3)在MainPage.xaml.cs中,将以下代码添加到OnNavigatedTo方法,就在Disable UI注释的正下方。
FlashButton.IsEnabled = false;
4)在MainPage.xaml.cs中,将以下代码添加到cam_Initialized方法,就在txtDebug语句的下面:
//设置flash按钮文字。
FlashButton.Content = "Fl:" + cam.FlashMode.ToString();
此代码显示FlashButton按钮上的当前闪光模式。
5)在MainPage.xaml.cs中,将以下代码添加到MainPage类。此代码通过在每次按下按钮时切换到不同的闪存模式来实现changeFlash_Clicked的事件处理程序。
// Activate a flash mode.
// Cycle through flash mode options when the flash button is pressed.
private void changeFlash_Clicked(object sender, RoutedEventArgs e)
{
switch (cam.FlashMode)
{
case FlashMode.Off:
if (cam.IsFlashModeSupported(FlashMode.On))
{
// Specify that flash should be used.
cam.FlashMode = FlashMode.On;
FlashButton.Content = "Fl:On";
currentFlashMode = "Flash mode: On";
}
break;
case FlashMode.On:
if (cam.IsFlashModeSupported(FlashMode.RedEyeReduction))
{
// Specify that the red-eye reduction flash should be used.
cam.FlashMode = FlashMode.RedEyeReduction;
FlashButton.Content = "Fl:RER";
currentFlashMode = "Flash mode: RedEyeReduction";
}
else if (cam.IsFlashModeSupported(FlashMode.Auto))
{
// If red-eye reduction is not supported, specify automatic mode.
cam.FlashMode = FlashMode.Auto;
FlashButton.Content = "Fl:Auto";
currentFlashMode = "Flash mode: Auto";
}
else
{
// If automatic is not supported, specify that no flash should be used.
cam.FlashMode = FlashMode.Off;
FlashButton.Content = "Fl:Off";
currentFlashMode = "Flash mode: Off";
}
break;
case FlashMode.RedEyeReduction:
if (cam.IsFlashModeSupported(FlashMode.Auto))
{
// Specify that the flash should be used in the automatic mode.
cam.FlashMode = FlashMode.Auto;
FlashButton.Content = "Fl:Auto";
currentFlashMode = "Flash mode: Auto";
}
else
{
// If automatic is not supported, specify that no flash should be used.
cam.FlashMode = FlashMode.Off;
FlashButton.Content = "Fl:Off";
currentFlashMode = "Flash mode: Off";
}
break;
case FlashMode.Auto:
if (cam.IsFlashModeSupported(FlashMode.Off))
{
// Specify that no flash should be used.
cam.FlashMode = FlashMode.Off;
FlashButton.Content = "Fl:Off";
currentFlashMode = "Flash mode: Off";
}
break;
}
// Display current flash mode.
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = currentFlashMode;
});
}