我想通过使用RaspberryPI3从IP Camera获取Image,我编写了这段代码,但是当我单击Button时,系统正在关闭,App.gics中引发异常,我该如何修复该代码?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.Web.Http;
namespace App6
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Sample()
{
Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri("http://192.168.1.253/SnapShotJPEG?Resolution=320x240&Quality=Motion")).OpenReadAsync();
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
byte[] bytes = pixelData.DetachPixelData();
BitmapImage image = new BitmapImage();
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
await stream.WriteAsync(bytes.AsBuffer());
stream.Seek(0);
await image.SetSourceAsync(stream);
}
IpCamera_1.Source = image; //IpCamera_1 is Image.
}
private void Hello_Click(object sender, RoutedEventArgs e)
{
Sample();
}
}
}
是否有其他解决方案将视频从IP Camera流式传输到Raspberry-Pi?我使用的是Windows-10-iot-core。
答案 0 :(得分:1)
由于您要连接到本地网络,因此您应该为Package.appxmanifest
添加一些必需的功能。右键单击解决方案资源管理器中的文件,选择View code
,然后在<Capabilities>
元素中添加以下内容:
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<Capability Name="privateNetworkClientServer" />
</Capabilities>
答案 1 :(得分:1)
请尝试将webcam
功能添加到Package.appxmanifest
。
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
<DeviceCapability Name="webcam" />
</Capabilities>
必须在通用Windows平台(UWP)应用程序包清单中声明功能,才能访问某些API或资源,如图片,音乐或相机或麦克风等设备。您可以参考App capability declarations。
网络摄像头功能可以访问内置摄像头或外部网络摄像头的视频,允许该应用捕获照片和视频。在Windows上,应用程序必须处理用户已从“设置”超级按钮禁用相机的情况。 网络摄像头功能仅授予对视频流的访问权限。为了授予对音频流的访问权限,必须添加麦克风功能。