码迷,mamicode.com
首页 > 编程语言 > 详细

C#程序中将图片转换为byte数组,并将byte数组转换为图片

时间:2015-08-11 15:32:00      阅读:631      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
/// 将图片以二进制流
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public byte[] SaveImage(String path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
return imgBytesIn;
}


/// <summary>
/// 现实二进制流代表的图片
/// </summary>
/// <param name="imgBytesIn"></param>
public void ShowImgByByte(byte[] imgBytesIn)
{
string NewImageName = "AAAA";//ImageName(CenterId);//获得图片的名字
string ImagePath = @"F:/AQPXImageURL/" + NewImageName.ToString() + ".jpg";

MemoryStream ms = new MemoryStream(imgBytesIn);

Bitmap bmp = new Bitmap(ms);
bmp.Save(ImagePath, ImageFormat.Bmp);
ms.Close();
//return NewImageName;

//pictureBox1.Image = Image.FromStream(ms);
}

/// <summary>
/// 这是用于测试
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btn_jituan_Click(object sender, EventArgs e)
{
byte[] bys = SaveImage("E:/LYX/SafeTrainAll_AQPX/SafeTrainAll_AQPX/DefaultModule/Exam/ExamImage/2015-08-10#2/00000052x1.jpg");
ShowImgByByte(bys);
}

C#程序中将图片转换为byte数组,并将byte数组转换为图片

标签:

原文地址:http://www.cnblogs.com/baofengxue00/p/4720852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!