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