#region 图片转二进制 /// <summary> /// 图片转二进制 /// </summary> /// <param name="imagepath">图片文件的路径</param> /// <returns>二进制</returns> public static byte[] GetPictureData(string imagepath) { /**/ ////根据图片文件的路径使用文件流打开,并保存为byte[] FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重载方法 byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); return byData; } #endregion #region 二进制转图片 /// <summary> /// 二进制转图片 /// </summary> /// <param name="streamByte">二进制</param> /// <returns>图片</returns> public static System.Drawing.Image ReturnPhoto(byte[] streamByte) { System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); return img; } #endregion #region 二进制转图片并保存在/UploadFiles/Image /// <summary> /// 二进制转图片并保存在/UploadFiles/Image /// </summary> /// <param name="streamByte">二进制</param> /// <returns>保存地址</returns> public static string Binary_Photo_Save(byte[] streamByte) { string time = DateTime.Now.ToString("yyyyMMddHHmmssffff"); System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); string uppath = System.Web.HttpContext.Current.Server.MapPath("~/UploadFiles/Image/") + "YMD_" + time + ".jpg"; img.Save(uppath); return "/UploadFiles/Image/YMD_" + time + ".jpg"; } #endregion