2016-04-26 152 views

回答

0

如果您的目標是手機或桌面,我會建議您創建一個c#Universal Windows App

要拍攝,您可以使用LowLagPhotoCapture獲得SoftwareBitmap

public async Task<SoftwareBitmap> takePhotoToSoftwareBitmap() 
    { 
     //initialize mediacapture with default camera 
     var mc = new MediaCapture(); 
     await mc.InitializeAsync(); 

     //create low lag capture and take photo 
     var lowLagCapture = await mc.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8)); 
     var photo = await lowLagCapture.CaptureAsync(); 

     //convert to displayable format 
     SoftwareBitmap displayableImage; 
     using (var frame = photo.Frame) 
     { 
      displayableImage = SoftwareBitmap.Convert(photo.Frame.SoftwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 
     } 

     return displayableImage; 
    } 

要了解如何使用(保存/顯示/編輯)一SoftwareBitmap看到Imaging How-To

欲瞭解更多Windows攝像頭文檔看到圖片GitHub Samples