C# BYTE转换成图像

MemoryStreamsr=newMemoryStream(b);Imagei=Bitmap.FromStream(sr,true);(这里)pictureBox1.I... MemoryStream sr=new MemoryStream(b);
Image i = Bitmap.FromStream(sr, true);(这里)
pictureBox1.Image = i;

老说参数无效
展开
 我来答
a124988724
2009-05-15
知道答主
回答量:30
采纳率:0%
帮助的人:0
展开全部
OpenFileDialog file = new OpenFileDialog();
if (file.ShowDialog() == DialogResult.OK)
{
//将图片读成文件流
FileStream fs = new FileStream(file.FileName, FileMode.Open);
byte[] b = new byte[int.Parse(fs.Length.ToString())];
//将文件流字节码放进数组
fs.Read(b,0,int.Parse(fs.Length.ToString()));
MemoryStream ms = new MemoryStream(b);
//转为图片
Image i = Bitmap.FromStream(ms, true);
pictureBox1.Image = i;
}

你把这段代码放到按钮里面 界面需要一个pictureBox控件支持
百度网友dc91b32
推荐于2016-02-15 · TA获得超过5650个赞
知道大有可为答主
回答量:5653
采纳率:0%
帮助的人:0
展开全部
public Image ByteArrayToImage(byte[] byteArrayIn, int count)
{
MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
小伊伊的账号
2009-05-15 · TA获得超过165个赞
知道小有建树答主
回答量:199
采纳率:0%
帮助的人:166万
展开全部
// height, width为图像高度和宽度

int widthByteLength = ((width * 24 + 15) & ~15) >> 3;
int imageSize = widthByteLength * height;
byte[] bytes = new byte[imageSize];

for (i = 0; i < heigth; i++)
{
byteIndex = i * widthByteLength;
for (j = 0; j < width; j++)
{
bytes[byteIndex++] = backGround.B;
bytes[byteIndex++] = backGround.G;
bytes[byteIndex++] = backGround.R;
}
}

Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
MemoryStream curImageStream = new MemoryStream();
bitmap.Save(curImageStream, System.Drawing.Imaging.ImageFormat.Bmp);
curImageStream.Flush();
byte[] tempData = new byte[4];
curImageStream.Position = 10;
curImageStream.Read(tempData, 0, 4);
int dataOffset = BitConverter.ToInt32(tempData, 0);
curImageStream.Position = dataOffset;
curImageStream.Write(bytes, 0, bytes.Length);
curImageStream.Flush();
bitmap = new Bitmap(curImageStream);

pictureBox1.Image = bitmap ;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式