byte array to image save throws an error like "Parameter not valid" in C#
<p>i could see this question is asked many many times but none seems to be straight forward answer. so am posting this question.</p>

<p>I am reading BLOB from oracle database into <strong>photoByteArray[]</strong> array. 
Now i just want to save this byte[] into file systems as <strong>anyFileName.jpeg</strong> (or any format), but i get the <strong>"Parameter not vaid</strong>" exception.</p>

<p>What i tried is </p>

<pre><code>using (var ms = new System.IO.MemoryStream(photoByteArray))
{
  using (var img = Image.FromStream(ms)) // error thrown here as 'parameter is not valid'
    {
      img.Save("D:\\anyFileName.jpg", ImageFormat.Jpeg); 
     }
 }
</code></pre>

<p><strong>My bytes</strong></p>

<p><strong><a href="https://i.stack.imgur.com/ad5Yo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ad5Yo.png" alt="Byte image"></a></strong></p>

<p>Few are suggesting that some header gets added in the byte array, but how and howmuch to remove that kind of header is not straight forward way.</p>

<p>What am i doing wrong ?</p>