简体   繁体   English

System.ArgumentException:“参数无效”内存流到图像

[英]System.ArgumentException: "Parameter is not Valid" Memorystream to Image

I have checked other StackOverflow Questions but none seem to help, as most of them work with a "base64string" this wont help me cause my byte[] is encoded with Windows-1252.我已经检查了其他 StackOverflow 问题,但似乎没有帮助,因为它们中的大多数都使用“base64string”,这对我没有帮助,因为我的 byte[] 是用 Windows-1252 编码的。

My Problem:我的问题:

I'm using a Barcode Scanner to make a Picture, I use Encoding.GetEncoding("Windows-1252").GetString(e.Buffer)) .我正在使用条形码扫描仪制作图片,我使用Encoding.GetEncoding("Windows-1252").GetString(e.Buffer)) e is the DataaReceivedEventArgs and it gives me a bytearray. e 是DataaReceivedEventArgs ,它给了我一个DataaReceivedEventArgs

I have to convert it to a string because I have to cut some parts out of the response this step has to stay.我必须将其转换为字符串,因为我必须从响应中删除一些部分,这一步必须保留。

I then use Encoding.GetEncoding("Windows-1252").GetBytes(response) to convert it to a ByteArray.然后我使用Encoding.GetEncoding("Windows-1252").GetBytes(response)将其转换为 ByteArray。

I then just make a MemoryStream and use it in Image.FromStream(ms) .然后我只制作一个MemoryStream并在Image.FromStream(ms)使用它。 The Problem is it WORKS the first time without any problems.问题是它工作在第一时间没有任何问题。 But after the Second time it gives me the Invalid Parameter Exception.但是在第二次之后它给了我无效的参数异常。

  byte[] bBytes = await responseZuBytesArray();

            using (MemoryStream ms = new MemoryStream(bBytes))
            {
                pcbBildAnzeige.SizeMode = PictureBoxSizeMode.StretchImage;
                pcbBildAnzeige.Image = Image.FromStream(ms);
            }

            tIsStarted = false;

i have tried setting the Position of the MemoryStream, tried to convert it to a Bitmap first.我尝试设置 MemoryStream 的位置,尝试先将其转换为位图。 i have tried so much but i think there is something simple im just not seeing thats why im asking here我已经尝试了很多,但我认为有一些简单的事情我只是没有看到这就是我在这里问的原因

尝试使用类System.Drawing.ImageConverter转换字节数组;

Bitmap bitmap = (Bitmap)new System.Drawing.ImageConverter().ConvertFrom(bBytes);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数无效-System.argumentException-图像处理 - Parameter not valid - System.argumentexception - Image Handling System.ArgumentException:参数无效 - System.ArgumentException: Parameter is not valid DrawToBitmap - System.ArgumentException:参数无效 - DrawToBitmap - System.ArgumentException: Parameter is not valid 给出“System.ArgumentException:'参数无效。' " 当我从数据库中检索图像时 - Gives "System.ArgumentException: 'Parameter is not valid.' " when i retrieving image from database System.ArgumentException:“参数无效。” 在 C# 中从 SQL Server 获取图像 - System.ArgumentException: 'Parameter is not valid.' in C# get image from SQL Server 更新 Access 数据库后检索图像时出现问题(System.ArgumentException:'参数无效。') - Problem retrieving the image after updating the Access database (System.ArgumentException: 'Parameter is not valid.') System.ArgumentException:参数无效。 GraphicsPath.AddString - System.ArgumentException: Parameter is not valid. GraphicsPath.AddString System.ArgumentException:参数无效。 在C#中 - System.ArgumentException: Parameter is not valid. in C# 计时器中graphics.DrawLine上的“ System.ArgumentException参数无效” - 'System.ArgumentException parameter is not valid' at graphics.DrawLine in a timer System.ArgumentException:'参数无效。 (showDialog错误) - System.ArgumentException: 'Parameter is not valid.' (showDialog error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM