问题描述
我有一个包含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);
推荐答案
这篇关于二进制文件到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!