错误"参数无效同时将字节转换为图像

问题描述:

我正在将字节转换为图像,但出现错误

I am converting bytes into an image but I get an error

参数无效

我正在粘贴我的代码.请检查代码并建议我做对还是错.

I am pasting my code. Kindly check the code and suggested that was I am doing right or wrong.

Image arr1 = byteArrayToImage(Bytess);

这是函数.

public static Image byteArrayToImage(byte[] byteArrayIn)
{
        if (null == byteArrayIn || byteArrayIn.Length == 0)
            return null;

        MemoryStream ms = new MemoryStream(byteArrayIn);
        try
          {
            Process currentProcess1 = Process.GetCurrentProcess();
            Image returnImage = Image.FromStream(ms);
            return returnImage;
          }
        catch (Exception ex)
          {
            MessageBox.Show(ex.Message);
          }
    }

我应用了许多技术和解决方案,但对我不起作用

I applied many techniques and solutions but it did not work for me

您的回答将不胜感激.

谢谢

试试这个

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

    return img;
}