Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Image.FromStream throws参数仅在linux上无效错误_C#_Linux_Image_Asp.net Core_File Upload - Fatal编程技术网

C# Image.FromStream throws参数仅在linux上无效错误

C# Image.FromStream throws参数仅在linux上无效错误,c#,linux,image,asp.net-core,file-upload,C#,Linux,Image,Asp.net Core,File Upload,我在.NETCore中做了一些单元测试,检查从angular前端上传的文件是否在后端调整了大小 我有一个测试中使用的服务,包含以下方法: public byte[] ResizeImage(IFormFile formFile) { Image imgFromStream; using (var memStream = new MemoryStream()) { formFile.CopyTo(memStream);

我在.NETCore中做了一些单元测试,检查从angular前端上传的文件是否在后端调整了大小

我有一个测试中使用的服务,包含以下方法:

public byte[] ResizeImage(IFormFile formFile)
    {
        Image imgFromStream;
        using (var memStream = new MemoryStream())
        {
            formFile.CopyTo(memStream);
            memStream.Position = 0;

            Console.WriteLine("$$$$$$$ LENGTH  :" + memStream.Length);
            Console.WriteLine("$$$$$$$ CAN READ :" + memStream.CanRead);
          

   
 ->>>>>           imgFromStream = System.Drawing.Image.FromStream(memStream, false,false);

            Image thumbnail = imgFromStream.GetThumbnailImage(280, 90, () => false, IntPtr.Zero);

            var imageByteArray = new byte[0];

            using (MemoryStream mStream = new MemoryStream())
            {
                thumbnail.Save(mStream, ImageFormat.Png);
                imageByteArray = mStream.ToArray();
            }
            imgFromStream.Dispose();
            thumbnail.Dispose();
            return imageByteArray;
        }

    }
问题是,只有在Linux机器上,测试才从(--->)行失败。 我试过使用ImageConverter,linux对此也有不好的看法,但它仍然不起作用。 我没有主意了

StackTrace :   at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
为测试创建映像的方法:

 public Image ByteArrayToImage(byte[] byteArrayIn)
    {
        int size = (int)Math.Sqrt(byteArrayIn.Length);

        Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format32bppArgb);
        BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

        try
        {
            for (int rowIndex = 0; rowIndex < bitmapData.Height; ++rowIndex)
                Marshal.Copy(byteArrayIn, rowIndex * bitmap.Width, bitmapData.Scan0 + rowIndex * bitmapData.Stride, bitmap.Width);
        }
        finally
        {
            bitmap.UnlockBits(bitmapData);
        }

        return bitmap;
    }

如果要在linux上使用
System.Drawing.Common
,则需要安装GDI+支持库:

sudo apt install libc6-dev 
sudo apt install libgdiplus

现在我记性不好了。在System.Drawing.Image.InitializeFromStream(Stream Stream)中,请参见,该文件可能不是有效的图像。您能看到我更新的问题吗?我已经添加了图像生成方法。您是否要从随机生成的字节创建图像?它在windows上工作吗?它在windows上工作,是的
sudo apt install libc6-dev 
sudo apt install libgdiplus