2016-04-13 10 views
2

なぜWindowsのドキュメントが欠けていますか?この方法がどのように動作するかの例を見つけることは不可能だと思われますStartPreviewToCustomSinkAsyncMediaCapture.StartPreviewToCustomSinkAsyncメソッドはどのように機能しますか?

私がやっているのは、ビデオソースから(MediaCapture経由で)プレビュー画像を取得していますが、第2のパラメータIMediaExtensionが/とされているもの)。

あなたのお役に立ってもらえますか?

答えて

1

を提供していたコードのようになり、マイクロソフトのgithubのページ上のサンプルがあり、その関連性はありますが、Windows 10をターゲットにしています。この機能を利用するには、プロジェクトを移行することができます。

GetPreviewFrame:このサンプルは、本格的な写真ではなくプレビューフレームをキャプチャします。プレビューフレームが作成されると、プレビューフレーム上のピクセルを編集できます。

は、ここで関連する部分である:

private async Task GetPreviewFrameAsSoftwareBitmapAsync() 
{ 
    // Get information about the preview 
    var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; 

    // Create the video frame to request a SoftwareBitmap preview frame 
    var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height); 

    // Capture the preview frame 
    using (var currentFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame)) 
    { 
     // Collect the resulting frame 
     SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap; 

     // Add a simple green filter effect to the SoftwareBitmap 
     EditPixels(previewFrame); 
    } 
} 

private unsafe void EditPixels(SoftwareBitmap bitmap) 
{ 
    // Effect is hard-coded to operate on BGRA8 format only 
    if (bitmap.BitmapPixelFormat == BitmapPixelFormat.Bgra8) 
    { 
     // In BGRA8 format, each pixel is defined by 4 bytes 
     const int BYTES_PER_PIXEL = 4; 

     using (var buffer = bitmap.LockBuffer(BitmapBufferAccessMode.ReadWrite)) 
     using (var reference = buffer.CreateReference()) 
     { 
      // Get a pointer to the pixel buffer 
      byte* data; 
      uint capacity; 
      ((IMemoryBufferByteAccess)reference).GetBuffer(out data, out capacity); 

      // Get information about the BitmapBuffer 
      var desc = buffer.GetPlaneDescription(0); 

      // Iterate over all pixels 
      for (uint row = 0; row < desc.Height; row++) 
      { 
       for (uint col = 0; col < desc.Width; col++) 
       { 
        // Index of the current pixel in the buffer (defined by the next 4 bytes, BGRA8) 
        var currPixel = desc.StartIndex + desc.Stride * row + BYTES_PER_PIXEL * col; 

        // Read the current pixel information into b,g,r channels (leave out alpha channel) 
        var b = data[currPixel + 0]; // Blue 
        var g = data[currPixel + 1]; // Green 
        var r = data[currPixel + 2]; // Red 

        // Boost the green channel, leave the other two untouched 
        data[currPixel + 0] = b; 
        data[currPixel + 1] = (byte)Math.Min(g + 80, 255); 
        data[currPixel + 2] = r; 
       } 
      } 
     } 
    } 
} 

そして、あなたのクラスの外にこれを宣言します。

[ComImport] 
[Guid("5b0d3235-4dba-4d44-865e-8f1d0e4fd04d")] 
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 
unsafe interface IMemoryBufferByteAccess 
{ 
    void GetBuffer(out byte* buffer, out uint capacity); 
} 

そしてもちろん、あなたのプロジェクトが動作するように、このすべてのために危険なコードを許可する必要があります。

すべての詳細を取得する方法については、サンプルを詳しく見てください。ウォークスルーを行うには、最新のビルド/カンファレンスのcamera sessionをご覧ください。これにはいくつかのカメラサンプルのウォークスルーが含まれています。あなたが8.1にバインドされている場合は別の方法として

、あなたはどれがnotify you when there's a new preview frame availableをすることができ、Lumia Imaging SDKに見ることができます。

+0

Lumia Imaging SDKを使用していないコードを残したいと思っていましたが、私もWP 8.1をターゲットにしていました。ありがとう – Moucheg

+0

この例は 'StartPreviewToCustomSinkAsync'機能を含んでいません。私はまだそれを使う方法をまだ知りません。 – ThoAppelsin

1

GitHubには多くの例があります。あなたがWindowsの携帯電話8.1のために開発している場合 - サンプルがhere
ある。このように見て記録this例をよる

private StspMediaSinkProxy mediaSink; 
mediaSink = new StspMediaSinkProxy(); 

MediaEncodingProfile encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga); 

var mfExtension = await mediaSink.InitializeAsync(encodingProfile.Audio, encodingProfile.Video); 
await mediaCapture.StartRecordToCustomSinkAsync(encodingProfile, mfExtension); 

だから、あなたは、この例からMediaEncodingProfileからIMediaExtensionを取得する方法を理解することができます。
あなたが任意のコードを投稿していませんが、プレビューを行うことは、私はあなたが必要とするすべては、すべての今して、プレビューのフレームを取得する場合

関連する問題