title: C++/CX How to create a BitmapImage from a buffer and buffer count
body: <p>I use the mediaCapture with AddEffectsAsync in order to set a MFT on the camera. Using that MFT I was able to return back the data for each frame, from the MFT. Now The bitmap comes as a Nokia::Ghraphics::Imaging::Bitmap class.
  In the following code, I take the size of the buffer and the buffer from it and send it to my application:</p>
  
  <pre><code>void TransformImage_NV12(
  const D2D_RECT_U &amp;rcDest,
  _Inout_updates_(_Inexpressible_(2 * lDestStride * dwHeightInPixels)) BYTE *pDest,
  _In_ LONG lDestStride,
  _In_reads_(_Inexpressible_(2 * lSrcStride * dwHeightInPixels)) const BYTE *pSrc,
  _In_ LONG lSrcStride,
  _In_ DWORD dwWidthInPixels,
  _In_ DWORD dwHeightInPixels,
  IVector&lt;IImageProvider^&gt;^ providers)
  {
  
      auto size = Windows::Foundation::Size(dwWidthInPixels, dwHeightInPixels);
      auto totalbytes = (int)dwHeightInPixels * (int)dwWidthInPixels * 3 / 2;
  
      Nokia::Graphics::Imaging::Bitmap^ m_BitmapToProcess = AsBitmapNV12(pSrc, (unsigned int)size.Width, (unsigned int)size.Height);
  
      BitmapImageSource^ source = ref new BitmapImageSource(m_BitmapToProcess);
      auto first = providers-&gt;GetAt(0);
      ((IImageConsumer^)first)-&gt;Source = source;
  
      auto last = providers-&gt;GetAt(providers-&gt;Size - 1);
  
      BitmapRenderer^ renderer = ref new BitmapRenderer(last, ColorMode::Yuv420Sp);
  
      auto renderOp = renderer-&gt;RenderAsync();
      auto renderTask = create_task(renderOp);
  
      renderTask.then([pDest, totalbytes](Nokia::Graphics::Imaging::Bitmap^ bitmap)
      {
          auto count = bitmap-&gt;Buffers-&gt;Length;
          unsigned char* data = FromIBuffer(bitmap-&gt;Buffers[0]-&gt;Buffer);
          CMFTWrapper::FrameData = data;
          CMFTWrapper::count = count;
          SetEvent(CMFTWrapper::FrameEvent());
          CopyMemory(pDest, data, totalbytes);
      }).wait();
  }
  </code></pre>
  
  <p>Doing this I have a callback being called in my application:</p>
  
  <pre><code>void VideoCapturerSampleCallback(struct LmiVideoCapturer_* capturer, const LmiVideoFrame* videoFrame, LmiVoidPtr userData)
  {
      App2::MainPage^ ctx = context;
      Windows::ApplicationModel::Core::CoreApplication::MainView-&gt;CoreWindow-&gt;Dispatcher-&gt;RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([ctx]()
      {          
          Windows::UI::Xaml::Media::Imaging::BitmapImage^ bitmapImage =
          ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
          //TODO will need to create it from the buffer
          media-&gt;Source = bitmapImage;
  }));
  }
  </code></pre>
  
  <p>Here I have access to the Buffer and the count from the MFT, by using CMFTWrapper class, in which I have saved the data.
  My question is how can I load this data inside my bitmapImage I created?
  I found some codes showing me how to build aa bitmapImage, but most of them are in C# and I need to use C++/cx</p>