Windows Phone 7 - 相机 Flash 应用程序无法运行 [英] Windows Phone 7 - Camera Flash App Not Functioning

查看:23
本文介绍了Windows Phone 7 - 相机 Flash 应用程序无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In attempting to follow the instructions here - http://msdn.microsoft.com/en-us/library/hh202949.aspx I have coded a very simple WP7 app to turn on the camera flash. Everything appears to work, except....the flash doesn't activate.

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

My phone is Samsung SGH-I917 (latest OS update), I am using the WP7 SDK 7.1, I've checked that the flash of my camera actually does work. I have also checked to make sure the following is in the WMAppManifest.xml file.

<Capability Name="ID_CAP_ISV_CAMERA" />

您在下面的代码中看到的 MessageBox 使用表明相机对象已正确初始化,支持 flashmode 并且已设置 FlashMode.On.然而......实际上不会打开闪光灯.我错过了什么?

The MessageBox use you see in my code below, indicates that the camera object has been initialized properly, the flashmode is supported and the FlashMode.On has been set. Yet...no flash will actually turn on. What am I missing?

代码如下:

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<CameraOperationCompletedEventArgs>(cam_Initialized);
        cam.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_CaptureCompleted);
        cam.CaptureImageAvailable += new EventHandler<ContentReadyEventArgs>(cam_CaptureImageAvailable);
        cam.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(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:

<phone:PhoneApplicationPage 
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="FlashLite" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <Canvas x:Name="viewfinderCanvas" HorizontalAlignment="Center" >
        <Canvas.Background>
            <VideoBrush x:Name="viewfinderBrush" />
        </Canvas.Background>
    </Canvas>
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Button Width="200" Height="100" Content="Flash" Click="Button_Click" />
    </Grid>
</Grid>

推荐答案

cam.FlashMode = FlashMode.On;

仅表示拍摄图像时闪光灯将被激活.

only indicates that the flash will be activated when capturing the image.

那是通过做来实现的

cam.CaptureImage();

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

EDIT : If you only want to trigger the flash, you can just call cam.Focus();

这篇关于Windows Phone 7 - 相机 Flash 应用程序无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆