【发布时间】:2014-12-10 12:30:12
【问题描述】:
这与测试仪器有关,但需要 C# 代码中的更多帮助。 我在这里做了更多关于我的问题的解释。 我向仪器发送命令,我只是从仪器接收数据。 接收到的数据是真实格式(二进制),我只是放入字符串变量。 在这里,我捕获了字符串中的内容..
http://i.stack.imgur.com/UcYqV.png
那么我想要做的是我想要这个字符串转换字节数组。因为我的目标是在我的电脑中制作 png 文件。仪器手册说这个返回的数据是gif格式,但返回的是真实类型。 我相信问题点是当我转换为字节数组时,有问题...... 有没有人有这种经历,.????
/// below is just send command to instrument that i want " Returns an image of the display in .gif format "
my6705B.WriteString("hcop:sdump:data?", true);
string image_format = my6705B.ReadString();
/// what's inside string image_format ??![i attached screenshot png file. this is what i received from instrument. (manual said this is Returns an image of the display in .gif format)][1] ![png file][2]
http://i.stack.imgur.com/UcYqV.png
/// now here i think i did something wrong,
/// the goal is i want change this return data to gif or png or image file.
/// any solution is ok for me
/// i just try that change this data to byte array and then try to change image file.
/// i think some error here because my code success to convert byte array then create image,,, error
//// i believe that i did something wrong in convert byte array.....
System.Text.UnicodeEncoding encode = new System.Text.UnicodeEncoding();
byte[] byte_array22 = encode.GetBytes(image_format);
MemoryStream ms4 = new MemoryStream(byte_array22);
Image image = Image.FromStream(ms4); //// error point
image.Save(@"C:\Users\Administrator\Desktop\imageTest.png");
我相信我的解释是在评论中。 让我再次解释一下,我的目标是将 gif 数据转换为图像文件。 仪器给我们返回 .gif 格式的显示图像。 我收到这个数据到字符串数组。 然后我只想使用此 gif 数据制作 png 或 jpg 文件。
请指教。
约瑟夫·崔
【问题讨论】:
-
您需要读取 ASCII 字符串,而不是 16 位 unicode。当前 encode.GetBytes(image_format) 返回类似于 { '#','\0','0','\0','G','\0','I','\0',' F','\0','8','\0','9','\0' ... } 您要么必须使用其他 API,要么使用 Encoding.ASCII.GetBytes( )。
-
我现在可以做的一件事是仪器数据格式是 ASC,所以我可以更改为 REAL 格式。那我们可以换一种方式吗??
-
我认为关键是仪器可以返回 asc 或 real 格式。所以我所做的是将格式设置为 asc,然后更改 Encoding.ASCII.GetBytes()。但 MemoryStream ms4 = new MemoryStream(byte_array22); 中的错误Image image = Image.FromStream(ms4, true, true);
标签: c# bytearray screenshot gif imagemagick-convert