title: Emgucv Image to texture2d on Unity
body: <pre><code>public class testEmguCV : MonoBehaviour
  {
      private Capture capture;
  
      void Start() 
      {
          capture = new Capture();
      }
  
      void Update()
      {
          Image&lt;Gray, Byte&gt; currentFrame = capture.QueryGrayFrame();
          Bitmap bitmapCurrentFrame = currentFrame.ToBitmap();
          MemoryStream m = new MemoryStream();
          bitmapCurrentFrame.Save(m, bitmapCurrentFrame.RawFormat);
  
          Texture2D camera = new Texture2D(400, 400);
          if (currentFrame != null)
          {
              camera.LoadImage(m.ToArray());
              renderer.material.mainTexture = camera;
          }
       }
  } 
  </code></pre>
  
  <p>I used above code to convert between camera feed from emgucv camera to texture2d in unity but i am having problem with <code>bitmapCurrentFrame.Save(m, bitmapCurrentFrame.RawFormat);</code> 
  it is giving following errors</p>
  
  <blockquote>
    <p>ArgumentNullException: Argument cannot be null. Parameter name:
    encoder System.Drawing.Image.Save (System.IO.Stream stream,
    System.Drawing.Imaging.ImageCodecInfo encoder,
    System.Drawing.Imaging.EncoderParameters encoderParams)
    System.Drawing.Image.Save (System.IO.Stream stream,
    System.Drawing.Imaging.ImageFormat format) (wrapper
    remoting-invoke-with-check) System.Drawing.Image:Save
    (System.IO.Stream,System.Drawing.Imaging.ImageFormat)
    WebcamUsingEmgucv.Update () (at Assets/WebcamUsingEmgucv.cs:51)</p>
  </blockquote>
  
  <p>After several hours of thinking and searching i dont know what is going on please help</p>