UWP:从网络摄像头捕获的图片未对齐:Windows.Media.Capture.MediaCapture.CapturePhotoToStorageFileAsync

时间:2016-08-14 09:49:52

标签: c# win-universal-app raspberry-pi2 windows-10-iot-core webcam-capture

我正在尝试从运行Windows IOT核心的Raspberry Pi 2上的网络摄像头捕获图片。有时我会得到未对齐的图片,如下所示。我遇到了不同网络摄像头的同样问题。错位似乎很随意。我每次捕捉时都会遇到不同的错位。请帮忙。

enter image description here enter image description here

这是代码。

    private Windows.Media.Capture.MediaCapture captureManager;
    private ImageEncodingProperties imgFormat;
    private StorageFolder myPictures;

    public Camera()
    {
        captureManager = new MediaCapture();
        captureManager.InitializeAsync().AsTask().Wait();
        imgFormat = ImageEncodingProperties.CreateJpeg();
        StorageLibrary pictureLibrary = Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures).AsTask().Result;
        myPictures = pictureLibrary.SaveFolder;
    }

    public StorageFile TakePictureToFile()
    {
        DateTime now = DateTime.Now;
        string foldername = now.ToString("ddMMyy");
        string filename = now.ToString("hh-mm-sstt fffffff");

        StorageFolder foldertosave = null;
        if (!Directory.Exists(myPictures.Path + "\\" + foldername))
        {
            foldertosave = myPictures.CreateFolderAsync(foldername).AsTask().Result;
        }
        else
        {
            foldertosave = myPictures.GetFolderAsync(foldername).AsTask().Result;
        }
        StorageFile file = foldertosave.CreateFileAsync(filename).AsTask().Result;

        captureManager.CapturePhotoToStorageFileAsync(imgFormat, file).AsTask().Wait();
        return file;
    }

0 个答案:

没有答案