title: C# encode bitmap JPEG and save it to byte[]
body: <p>I have this code that saves an image to disk</p>
  
  <pre><code>public static void SaveImage(Bitmap picture, string path)
      {
  
          // Comprimir
          ImageCodecInfo encoder = GetJPGEncoder();
  
          // Create an Encoder object based on the GUID
          // for the Quality parameter category.
          System.Drawing.Imaging.Encoder myEncoder =
              System.Drawing.Imaging.Encoder.Quality;
  
          // Create an EncoderParameters object.
          // An EncoderParameters object has an array of EncoderParameter
          // objects. In this case, there is only one
          // EncoderParameter object in the array.
          EncoderParameters myEncoderParameters = new EncoderParameters(1);
          EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
          myEncoderParameters.Param[0] = myEncoderParameter;
  
          //picture.
          picture.Save(path, encoder, myEncoderParameters);
  
      }
  </code></pre>
  
  <p>but now I need to get the result as a byte[]. I can't find a way to get the result in memory so that I can convert it to byte[]. I thought about loading the file after saving it in the harddrive, but that would be completely unnecessary. Does anyone know if I can achieve this?</p>