title: Output of System.Drawing.Image Save is not the same as what fed into Image.FromStream
body: <p>I am trying to validate an image submitted to backend in Base64 string format by parsing it into an Image object, extracting it from the same Image object and finally comparing input byte array and output byte array assuming these two should be the same or there was something wrong in the input image. Here is the code:</p>
  
  <pre><code>    private void UpdatePhoto(string photoBase64) 
      {
          var imageDataInBytes = Convert.FromBase64String(photoBase64);
          ValidateImageContent(imageDataInBytes);
      }
  
  
      private void ValidateImageContent(byte[] imageDataInBytes)
      {
          using (var inputMem = new MemoryStream(imageDataInBytes))
          {
              var img = Image.FromStream(inputMem, false, true);
  
              using (MemoryStream outputMemStream = new MemoryStream())
              {
                  img.Save(outputMemStream, img.RawFormat);
                  var outputSerialized = outputMemStream.ToArray();
  
                  if (!outputSerialized.SequenceEqual(imageDataInBytes))
                      throw new Exception("Invalid image. Identified extra data in the input. Please upload another photo.");
              }
          }
      }
  </code></pre>
  
  <p>and it fails on an image that I know is a valid one. </p>
  
  <p>Is my assumption wrong that output of Image.Save must be the same as what Image.FromStream is fed with? Is there a way to correct this logic to achieve this way of validation correctly?</p>