C# 从流中读取位图
我有一个网络流,它发送名称和图片。名称和图片以一个特定的单词开始和结尾 例子: beginnamexxxxxxxxendnamebeginpyyyyyyyyyendpic 我将在块中收集流,并检查最后一个块是否包含图片的停止单词。
byte[] data = new byte[2048];
int numBytesRead = stream.Read(data, 0, 2048);
if (numBytesRead > 0)
{
code += Encoding.ASCII.GetString(data, 0, numBytesRead);
}
如果是,我将停止收集并将字符串分为名称部分和图片部分。 原则上,我现在应该只有一个包含图片的字符串。 之后,我尝试将其保存为映像,但我只在最后一个代码步骤
byte[] toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes(code);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Position = 0;
var image = Image.FromStream(ms, true);
异常中得到一个例外:system.argumentException'system.drawing.dll
有什么想法可能是什么问题?
I've a network stream which sends a name and a picture. Name and picture start and end with a specific word
Example:
BeginNameXXXXXXXEndNameBeginPicYYYYYYYYYEndPic
I'll collect the stream in blocks and check if the last block contains the stop word of the picture.
byte[] data = new byte[2048];
int numBytesRead = stream.Read(data, 0, 2048);
if (numBytesRead > 0)
{
code += Encoding.ASCII.GetString(data, 0, numBytesRead);
}
If yes I'll stop collecting and divide the String into the name part and the picture part.
In principle I should have now a string only containing the picture.
Afterwards I try to save it as image but I only get an exception on the last code step
byte[] toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes(code);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Position = 0;
var image = Image.FromStream(ms, true);
Exception thrown: 'System.ArgumentException' in System.Drawing.dll
Any ideas what could be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论