二进制文件到图像文件 [英] binary file to image file

查看:66
本文介绍了二进制文件到图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含jpg文件的二进制流文件.我得到了流&中所有jpg的起始字节和结束字节.将字节数组转换为图像文件时放入字节数组,它将剪切图像的代码:byte [] imgStartSequence = new byte [] { 0xFF,0xD8、0xFF,0xE0};
start1 = IndexOfSequence(TMP,imgStartSequence,end1);//
byte [] imgEndSequence =新的byte [] {0xFF,0xD9};
end1 = IndexOfSequence(TMP,imgEndSequence,start1);//
int imgLength =(end1 + 1)-(start1 + 2);//
byte [] IMG =新的byte [imgLength];
Array.Copy(TMP,start1,IMG,0,imgLength);
MemoryStream ms =新的MemoryStream(IMG);
PictureBox p = new PictureBox();
p.Image = Image.FromStream(ms,true);
p.Location =新的System.Drawing.Point(x,y);
p.Size =新的System.Drawing.Size(200,200);
p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Controls.Add(p);

I have a binary stream file that contains jpg file. I get the start bytes end the end bytes of any jpg in the stream & put to byte array when converting the byte array to image file, it cut the image the code: byte[] imgStartSequence = new byte[] { 0xFF, 0xD8, 0xFF, 0xE0};
start1 = IndexOfSequence(TMP, imgStartSequence, end1);//
byte[] imgEndSequence = new byte[] { 0xFF, 0xD9 };
end1 = IndexOfSequence(TMP, imgEndSequence, start1);//
int imgLength = (end1+1) - (start1 + 2);//
byte[] IMG = new byte[imgLength];
Array.Copy(TMP, start1, IMG, 0, imgLength);
MemoryStream ms = new MemoryStream(IMG);
PictureBox p = new PictureBox();
p.Image = Image.FromStream(ms, true);
p.Location = new System.Drawing.Point(x, y);
p.Size = new System.Drawing.Size(200, 200);
p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Controls.Add(p);

推荐答案

可能是序列 FF D9 不仅出现在图像流的末尾.开始序列也可以出现在图像主体内部.

Probably the sequence FF D9 appears not only at the end of the image stream. The start sequence can appears inside the image body too.


这篇关于二进制文件到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆