C# 无法将图像转换为bytearray

C# 无法将图像转换为bytearray,c#,C#,我正在尝试转换字节数组中的picturebox MemoryStream s = new MemoryStream(); picProfilePicture.Image.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] pic = s.ToArray(); 但是当我使用这个方法时,我在GDI+中得到了一般性的错误。如何解决此问题?请参考此链接中的答案 FileStream fs = new FileStream(selec

我正在尝试转换字节数组中的picturebox

MemoryStream s = new MemoryStream();
picProfilePicture.Image.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = s.ToArray();
但是当我使用这个方法时,我在GDI+中得到了一般性的错误。如何解决此问题?

请参考此链接中的答案
    FileStream fs = new FileStream(selectedFile, FileMode.Open, FileAccess.Read);
    byte[] bimage = new byte[fs.Length];
    fs.Read(bimage, 0, Convert.ToInt32(fs.Length));