110,499
社区成员
发帖
与我相关
我的任务
分享
//Imagepath 为图片路径
//将图片转换为byte[] imagebinnary
//直接将imagebinnary保存进数据库
public static object imagetobyte( string Imagepath)
{
if (Imagepath != "") //检查图片路径是否为空
{
FileStream filestream = new FileStream(Imagepath, FileMode.Open);
BinaryReader binnaryreader = new BinaryReader(filestream);
byte[] imagebinnary = binnaryreader.ReadBytes((int)filestream.Length);
binnaryreader.Close();
filestream.Close();
return imagebinnary;
}
else
{
return DBNull.Value;
}
}
/// <summary>
/// 将二进制图片转为图片
/// </summary>
public static void Convert_byte_To_Image()
{
byte[] Imagebyte = (byte[]) XXXX ; // XXX为图片数组
MemoryStream stream = new MemoryStream(Imagebyte);//图片数组转为内存文件流
MyPictureBox.Image = new Bitmap(stream);
stream.Close();
}