Windows phone 7 如何在Windows Phone 7中使用反射停止led手电筒/手电筒应用程序
我正在制作一个手电筒应用程序,在这个应用程序中,我需要不断地使用相机的LED来打开和关闭同一个按钮。我看了这篇文章。开/关操作只能正常工作一次。守则如下:Windows phone 7 如何在Windows Phone 7中使用反射停止led手电筒/手电筒应用程序,windows-phone-7,windows-phone-7.1,windows-phone-7.1.1,Windows Phone 7,Windows Phone 7.1,Windows Phone 7.1.1,我正在制作一个手电筒应用程序,在这个应用程序中,我需要不断地使用相机的LED来打开和关闭同一个按钮。我看了这篇文章。开/关操作只能正常工作一次。守则如下: private VideoCamera _videoCamera; private VideoCameraVisualizer _videoCameraVisualizer; bool _isFlashOff = true; private void FlashButton_Click(object sender, RoutedEv
private VideoCamera _videoCamera;
private VideoCameraVisualizer _videoCameraVisualizer;
bool _isFlashOff = true;
private void FlashButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (_isFlashOff)
{
_isFlashOff = false;
// Check to see if the camera is available on the device.
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
// Use standard camera on back of device.
_videoCamera = new VideoCamera();
// Event is fired when the video camera object has been initialized.
_videoCamera.Initialized += VideoCamera_Initialized;
// Add the photo camera to the video source
_videoCameraVisualizer = new VideoCameraVisualizer();
_videoCameraVisualizer.SetSource(_videoCamera);
}
}
else
{
_isFlashOff = true;
_videoCamera.StopRecording();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void VideoCamera_Initialized(object sender, EventArgs e)
{
_videoCamera.LampEnabled = true;
_videoCamera.StartRecording();
}
因为在VideoCamera类中没有实现文章中指定的停止录制方法。我的职能是:
public void StopRecording()
{
// Invoke the stop recording method on the video camera object.
_videoCameraStopRecordingMethod.Invoke(_videoCamera, null);
}
问题是当我再次按下按钮时,“Exception”被抛出为“TargetInvocationException”。我无法找出导致异常的问题。StopRecording()函数正确吗?。\n请尝试以下操作:
这是因为您应该只初始化相机一次。请在
on导航到
事件期间执行此操作,然后重新使用相同的实例:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Use standard camera on back of device.
_videoCamera = new VideoCamera();
// Event is fired when the video camera object has been initialized.
_videoCamera.Initialized += VideoCamera_Initialized;
// Add the photo camera to the video source
_videoCameraVisualizer = new VideoCameraVisualizer();
_videoCameraVisualizer.SetSource(_videoCamera);
}
private void VideoCamera_Initialized(object sender, EventArgs e)
{
isInitialized = true;
}
bool isInitialized;
bool isFlashEnabled;
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (!isInitialized)
{
MessageBox.Show("Please wait during camera initialization");
return;
}
if (!isFlashEnabled)
{
isFlashEnabled = true;
// Check to see if the camera is available on the device.
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
_videoCamera.LampEnabled = true;
_videoCamera.StartRecording();
}
}
else
{
isFlashEnabled = false;
_videoCamera.StopRecording();
}
}
您如何实例化
\u videoCameraStopRecordingMethod
?我已将其声明为:private MethodInfo\u videoCameraStopRecordingMethod并实例化为\u videoCameraStopRecordingMethod=videoCameraType.GetMethod(“StopRecording”);公共void StopRecording()是否有任何问题方法…?有人能帮我吗…?我需要如何创建StopRecording()方法…?Awesum回复…非常感谢!!!!KooKiz…你救了我一天…真的非常感谢你的回复…再问一个问题,我怎样才能实现这个手电筒的闪烁功能…@Shaan_14我想,当手电筒滴答作响时,打开或关闭手电筒。当我按下后退按钮移动时,代码出现问题到主页并再次导航到Flashlight页面,我在OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)方法的第_videoCameraVisualizer.SetSource(_videoCamera);行中得到“TargetInvestoryException”异常。而如果我按下Windows按钮或搜索按钮,它就会开始工作。。