Error" Parameter is not valid " while converting Bytes into Image

try this

public Image byteArrayToImage(byte[] byteArrayIn)
{
    System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
    Image img = (Image)converter.ConvertFrom(byteArrayIn);

    return img;
}

After trying many things I found a way which has a little bit more control. In this example you can specify the pixel format and copy the bytes to a Bitmap.

byte[] buffer = GetImageBytes();
var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
var bitmap_data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(buffer, 0, bitmap_data.Scan0, buffer.Length);
bitmap.UnlockBits(bitmap_data);
var result = bitmap as Image;