Mat*_*att 2 c# xaml camera windows-phone-8
我的视频在我的手机上显示photocapture设备的方向有问题.它实际上应该像内置相机应用程序一样灵活,这意味着它应该工作
其中至少有一个总是错误的.我尝试了https://projects.developer.nokia.com/cameraexplorer以使它工作,但即使它有最好的方法,它不适合我在不同的页面方向和前置摄像头旋转错误的方式(逆时针旋转时我旋转我的顺时针拨打电话,所以我倒过来了.
是否有任何代码片段与完整的工作相机videobrush?
要正确显示取景器,您需要两个信息:
首先,你需要一个以videobrush为背景的画布
<Canvas x:Name="viewfinderCanvas" Width="480" Height="800" >
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush" Stretch="None" />
</Canvas.Background>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
您必须使用Stretch ="None"或XAML将在视图刷上应用缩放.现在您需要viewfinderBrush转换才能正确显示它.默认情况下,画布中心对应于预览图片中心,因此我们需要计算角度,比例因子并使用画布中心作为转换中心.
要计算您需要的角度:
代码:
double ComputeAngle(PageOrientation orientation)
{
if ((orientation & PageOrientation.Portrait) == PageOrientation.Portrait)
{
return m_captureDevice.SensorRotationInDegrees;
}
else if ((orientation & PageOrientation.LandscapeLeft) == PageOrientation.LandscapeLeft)
{
return m_captureDevice.SensorRotationInDegrees - 90;
}
else //PageOrientation.LandscapeRight
{
return m_captureDevice.SensorRotationInDegrees + 90;
}
}
Run Code Online (Sandbox Code Playgroud)
缩放只是画布尺寸和预览图片尺寸之间的因素:
//orient preview picture size from the computed anle.
var tmp = new CompositeTransform(){Rotation = ComputeAngle(currentPageOrientation)};
var previewSize = tmp.TransformBounds (new Rect(new Point(), new Size(m_captureDevice.PreviewResolution.Width, m_captureDevice.PreviewResolution.Height))).Size;
double s1 = viewfinderCanvas.Width/ (double)previewSize.Width;
double s2 = viewfinderCanvas.Height/ (double)previewSize.Height;
Run Code Online (Sandbox Code Playgroud)
前置和后置摄像头的眼睛方向相反.因此,要正确显示前置摄像头,您需要在一个维度上应用镜像.在WP8上,传感器方向通常为90°,因此Y尺寸相反.
if (sensorLocation == CameraSensorLocation.Back)
{
viewfinderBrush.Transform = new CompositeTransform() {
Rotation = ComputeAngle(currentPageOrientation),
CenterX = viewfinderCanvas.Width / 2,
CenterY = viewfinderCanvas.Height / 2,
ScaleX = scale,
ScaleY = scale };
}
else
{
viewfinderBrush.Transform = new CompositeTransform() {
Rotation = ComputeAngle(currentPageOrientation),
CenterX = viewfinderCanvas.Width / 2,
CenterY = viewfinderCanvas.Height / 2,
ScaleX = scale,
ScaleY = -1 * scale };//Y mirror
}
Run Code Online (Sandbox Code Playgroud)
您可以在github上找到该示例的最新版本:https://github.com/yan-verdavaine/wp8-sample/tree/master/Imaging/ViewFinder
| 归档时间: |
|
| 查看次数: |
1643 次 |
| 最近记录: |