C# PhotoCamera API:如何正确处理?
我正在使用C# PhotoCamera API:如何正确处理?,c#,windows-phone-7,xaml,camera,windows-phone-8,C#,Windows Phone 7,Xaml,Camera,Windows Phone 8,我正在使用PhotoCameraAPI构建二维码扫描页面(使用ZXing)。然而,此页面只是应用程序的一小部分,因此并不总是显示。因此,应用程序在这个页面和其他一些带有公共控件的页面之间导航 问题是,有时扫描后,整个应用程序会在没有真正原因的情况下降低到30fps,而不是60fps。我怀疑摄像头仍在后台运行,帧同步将应用程序锁定为30fps,这就是我的问题:如何正确处理使用PhotoCameraAPI的页面? 我的XAML: <Grid Background="Black">
PhotoCamera
API构建二维码扫描页面(使用ZXing)。然而,此页面只是应用程序的一小部分,因此并不总是显示。因此,应用程序在这个页面和其他一些带有公共控件的页面之间导航
问题是,有时扫描后,整个应用程序会在没有真正原因的情况下降低到30fps,而不是60fps。我怀疑摄像头仍在后台运行,帧同步将应用程序锁定为30fps,这就是我的问题:如何正确处理使用PhotoCamera
API的页面?
我的XAML:
<Grid Background="Black">
<ProgressBar x:Name="PBar" IsIndeterminate="True" VerticalAlignment="Center" />
<Rectangle x:Name="ScanRect">
<Rectangle.Fill>
<VideoBrush x:Name="ScanVideoBrush" />
</Rectangle.Fill>
</Rectangle>
</Grid>
注意:我正在Lumia 920上测试应用程序。调用cam.Dispose()代码>应该处理图像源流和相机对象使用的免费资源,这样就可以了
您确定正在释放内存,即取消订阅PhotoCamera类活动吗
什么时候调用StopScan
方法?一个好的做法是在PhoneApplicationPage
的on导航中调用它
以下是MSDN中处理光电摄像机的代码示例:
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
if (cam != null)
{
// Dispose camera to minimize power consumption and to expedite shutdown.
cam.Dispose();
// Release memory, ensure garbage collection.
cam.Initialized -= cam_Initialized;
cam.CaptureCompleted -= cam_CaptureCompleted;
cam.CaptureImageAvailable -= cam_CaptureImageAvailable;
cam.CaptureThumbnailAvailable -= cam_CaptureThumbnailAvailable;
cam.AutoFocusCompleted -= cam_AutoFocusCompleted;
CameraButtons.ShutterKeyHalfPressed -= OnButtonHalfPress;
CameraButtons.ShutterKeyPressed -= OnButtonFullPress;
CameraButtons.ShutterKeyReleased -= OnButtonRelease;
}
}
我知道,我完全按照msdn所说的做了,但仍不时有一些背景信息。我将尝试更深入地分析该应用程序。谢谢。你处理相机成功了吗?看来我和你有同样的问题
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
if (cam != null)
{
// Dispose camera to minimize power consumption and to expedite shutdown.
cam.Dispose();
// Release memory, ensure garbage collection.
cam.Initialized -= cam_Initialized;
cam.CaptureCompleted -= cam_CaptureCompleted;
cam.CaptureImageAvailable -= cam_CaptureImageAvailable;
cam.CaptureThumbnailAvailable -= cam_CaptureThumbnailAvailable;
cam.AutoFocusCompleted -= cam_AutoFocusCompleted;
CameraButtons.ShutterKeyHalfPressed -= OnButtonHalfPress;
CameraButtons.ShutterKeyPressed -= OnButtonFullPress;
CameraButtons.ShutterKeyReleased -= OnButtonRelease;
}
}