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;
老说参数无效 展开
Image i = Bitmap.FromStream(sr, true);(这里)
pictureBox1.Image = i;
老说参数无效 展开
3个回答
展开全部
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控件支持
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控件支持
展开全部
public Image ByteArrayToImage(byte[] byteArrayIn, int count)
{
MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
{
MemoryStream ms = new MemoryStream(byteArrayIn, 0, count);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
// 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 ;
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 ;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询