C# 摄像机闪光灯

C# 摄像机闪光灯,c#,windows-phone-7,C#,Windows Phone 7,我在网上找到了一个永久打开闪光灯的教程()。在StartRecording()方法中,我在两次调用该方法时遇到异常。还有,我怎样才能停止录音??多谢各位 我上了这两门课 摄像机类: public class VideoCamera { private object _videoCamera; private PropertyInfo _videoCameraLampEnabledPropertyInfo; private MethodInfo _videoCameraSt

我在网上找到了一个永久打开闪光灯的教程()。在StartRecording()方法中,我在两次调用该方法时遇到异常。还有,我怎样才能停止录音??多谢各位

我上了这两门课

摄像机类:

public class VideoCamera
{
    private object _videoCamera;
    private PropertyInfo _videoCameraLampEnabledPropertyInfo;
    private MethodInfo _videoCameraStartRecordingMethod;
    private MethodInfo _videoCameraStopRecordingMethod;
    private EventHandler _videoCameraInitialized;

    public object InnerCameraObject
    {
        get { return _videoCamera; }
    }

    public bool LampEnabled
    {
        get { return (bool)_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, new object[0]); }
        set { _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, new object[] { value }); }
    }

    public VideoCamera()
    {
        // Load the media extended assembly which contains the extended video camera object.
        Assembly mediaExtendedAssembly = Assembly.Load("Microsoft.Phone.Media.Extended, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e");

        // Get the camera source type (primary camera).
        Type cameraSourceType = mediaExtendedAssembly.GetType("Microsoft.Phone.CameraSource");
        FieldInfo field = cameraSourceType.GetField("PrimaryCamera");
        object cameraSource = Enum.ToObject(cameraSourceType, (int)field.GetValue(cameraSourceType));

        // Create the video camera object.
        Type videoCameraType = mediaExtendedAssembly.GetType("Microsoft.Phone.VideoCamera");
        ConstructorInfo videoCameraConstructor = videoCameraType.GetConstructor(new Type[] { cameraSourceType });
        _videoCamera = videoCameraConstructor.Invoke(new object[] { cameraSource });

        // Set the properties and methods.
        _videoCameraLampEnabledPropertyInfo = videoCameraType.GetProperty("LampEnabled");
        _videoCameraStartRecordingMethod = videoCameraType.GetMethod("StartRecording");
        _videoCameraStopRecordingMethod = videoCameraType.GetMethod("StopRecording");

        // Let the initialize event bubble through.
        _videoCameraInitialized = new EventHandler(VideoCamera_Initialized);
        MethodInfo addInitializedEventMethodInfo = videoCameraType.GetMethod("add_Initialized");
        addInitializedEventMethodInfo.Invoke(_videoCamera, new object[] { _videoCameraInitialized });
    }

    /// <summary>
    /// Occurs when the camera object has been initialized.
    /// </summary>
    public event EventHandler Initialized;

    /// <summary>
    /// Videoes the camera_ initialized.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="eventArgs">The event args.</param>
    private void VideoCamera_Initialized(object sender, object eventArgs)
    {
        if (Initialized != null)
        {
            Initialized.Invoke(this, new EventArgs());
        }
    }
    public bool IsRecording { get; private set; }
    /// <summary>
    /// Start recording.
    /// </summary>
    public void StartRecording()
    {
         _videoCameraStartRecordingMethod.Invoke(_videoCamera, new object[0]);
    }

    public void StopRecording()
    {

    }
}
}

现在在主页上,我有一个错误代码

    private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
    {
        // Check to see if the camera is available on the device.
        if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
        {
            // Use standard camera on back of device.
            videoCam = new VideoCamera();

            // Event is fired when the video camera object has been initialized.
            videoCam.Initialized += VideoCamera_Initialized;

            // Add the photo camera to the video source
            CameraVisualizer = new VideoCameraVisualizer();
            CameraVisualizer.SetSource(videoCam);
        }
        else MessageBox.Show("No Flash supported for Your Device. Try Color Button");
    }

    private void VideoCamera_Initialized(object sender, EventArgs e)
    {
        videoCam.LampEnabled = true;
        videoCam.StartRecording();
        count++;
    }



    private void FlashButton_Click(object sender, RoutedEventArgs e)
    {
        if (count % 2 == 0)
        {

            videoCam.LampEnabled = true;
            videoCam.StartRecording();
        }
        else
        {

            videoCam.LampEnabled = false;
            videoCam.StopRecording();
        }
        count++;
    }

}

}提高你的谷歌技能!;)


另外,这是一篇关于这个主题的不错的博文

很抱歉,但我搜索了很多:/i我找不到这篇博文!!无论如何,非常感谢你
    private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
    {
        // Check to see if the camera is available on the device.
        if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
        {
            // Use standard camera on back of device.
            videoCam = new VideoCamera();

            // Event is fired when the video camera object has been initialized.
            videoCam.Initialized += VideoCamera_Initialized;

            // Add the photo camera to the video source
            CameraVisualizer = new VideoCameraVisualizer();
            CameraVisualizer.SetSource(videoCam);
        }
        else MessageBox.Show("No Flash supported for Your Device. Try Color Button");
    }

    private void VideoCamera_Initialized(object sender, EventArgs e)
    {
        videoCam.LampEnabled = true;
        videoCam.StartRecording();
        count++;
    }



    private void FlashButton_Click(object sender, RoutedEventArgs e)
    {
        if (count % 2 == 0)
        {

            videoCam.LampEnabled = true;
            videoCam.StartRecording();
        }
        else
        {

            videoCam.LampEnabled = false;
            videoCam.StopRecording();
        }
        count++;
    }

}