简体   繁体   English

从 IP 摄像头获取位图图像,UWP

[英]Get a BitMap Image from IP Camera, UWP

I want to get Image from IP Camera with using RaspberryPI3, that I wrote this code but when I click Button, system is going down, an exception thrown in App.gics, How can I fix that code?我想使用 RaspberryPI3 从 IP 摄像头获取图像,我编写了这段代码,但是当我单击 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();
    }
}
}

Is there another solution that streaming video from IP Camera to Raspberry-Pi?是否有另一种解决方案可以将视频从 IP 摄像机流式传输到 Raspberry Pi? I am using Windows-10-iot-core.我正在使用 Windows-10-iot-core。

Because you are connecting to local network, you should add some required capabilities to your Package.appxmanifest .因为您正在连接到本地网络,所以您应该向Package.appxmanifest添加一些必需的功能。 Right-click the file in solution explorer, select View code and in the <Capabilities> element add the following:右键单击解决方案资源管理器中的文件,选择View code并在<Capabilities>元素中添加以下内容:

<Capabilities>
  <Capability Name="internetClient" />
  <Capability Name="internetClientServer" />
  <Capability Name="privateNetworkClientServer" />
</Capabilities>

Please try to add the webcam capability to your Package.appxmanifest .请尝试将webcam功能添加到您的Package.appxmanifest

  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="privateNetworkClientServer" />
    <Capability Name="internetClientServer" />
    <DeviceCapability Name="webcam" />
  </Capabilities>

Capabilities must be declared in your Universal Windows Platform (UWP) app's package manifest to access certain API or resources like pictures, music, or devices like the camera or the microphone.必须在通用 Windows 平台 (UWP) 应用程序包清单中声明功能,才能访问某些 API 或资源(如图片、音乐)或设备(如相机或麦克风)。 You can refer to App capability declarations .可以参考应用能力声明

The webcam capability provides access to the video feed of a built-in camera or external webcam, which allows the app to capture photos and videos.网络摄像头功能提供对内置摄像头或外部网络摄像头的视频源的访问,这允许应用程序捕获照片和视频。 On Windows, apps must handle the case in which the user has disabled the camera from the Settings charm.在 Windows 上,应用程序必须处理用户从“设置”超级按钮禁用相机的情况。 The webcam capability only grants access to the video stream.网络摄像头功能仅授予对视频流的访问权限。 In order to grant access to the audio stream as well, the microphone capability must be added.为了也授予对音频流的访问权限,必须添加麦克风功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM