简体   繁体   中英

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.

My Problem:

I'm using a Barcode Scanner to make a Picture, I use Encoding.GetEncoding("Windows-1252").GetString(e.Buffer)) . e is the DataaReceivedEventArgs and it gives me a bytearray.

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.

I then just make a MemoryStream and use it in 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. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM