首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows Phone 7-相机Flash应用程序无法正常工作

Windows Phone 7-相机Flash应用程序无法正常工作
EN

Stack Overflow用户
提问于 2012-07-16 04:36:29
回答 1查看 1.7K关注 0票数 1

在尝试遵循这里的说明- http://msdn.microsoft.com/en-us/library/hh202949.aspx,我已经编写了一个非常简单的WP7应用程序来打开相机闪光灯。一切似乎都正常,except....the闪存不能激活。

我的手机是三星SGH-I917 (最新的操作系统更新),我正在使用WP7 SDK7.1,我已经检查了我相机的闪光灯是否真的可以工作。我还进行了检查,以确保以下内容在WMAppManifest.xml文件中。

代码语言:javascript
复制
<Capability Name="ID_CAP_ISV_CAMERA" />

你在下面的代码中看到的MessageBox用法,表明相机对象已经正确初始化,支持闪光模式,并且已经设置了FlashMode.On。Yet...no闪光灯实际上会打开。我遗漏了什么?

代码如下:

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-16 15:11:24

代码语言:javascript
复制
cam.FlashMode = FlashMode.On;

仅表示在采集图像时会激活闪光灯。

这是通过这样做来实现的

代码语言:javascript
复制
cam.CaptureImage();

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11495426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档