/// <summary>
/// 将图片以二进制流
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public string SaveImage(String path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
Encoding myEncoding = Encoding.GetEncoding("utf-8");
string stImageByte = Convert.ToBase64String(imgBytesIn);
return stImageByte;
}
/// <summary>
/// 现实二进制流代表的图片
/// </summary>
/// <param name="imgBytesIn"></param>
public void ShowImgByByte(string stImageByte)
{
string NewImageName = "AAAA";//ImageName(CenterId);//获得图片的名字
string ImagePath = @"F:/AQPXImageURL/" + NewImageName.ToString() + ".jpg";
byte[] imgBytesIn = Convert.FromBase64String(stImageByte);
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)
{
string bys = SaveImage("E:/LYX/SafeTrainAll_AQPX/SafeTrainAll_AQPX/DefaultModule/Exam/ExamImage/2015-08-10#2/00000052x1.jpg");
ShowImgByByte(bys);
}