mvc将图片转换为二进制保存到数据库的实例
1个回答
展开全部
二进制的网上应该可以找到相关例子
其实还有一种方案是把图片转换为Base64编码
/// <summary>
/// 将图片数据转换为Base64字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToBase64(object sender, EventArgs e)
{
Image img = this.pictureBox.Image;
BinaryFormatter binFormatter = new BinaryFormatter();
MemoryStream memStream = new MemoryStream();
binFormatter.Serialize(memStream, img);
byte[] bytes = memStream.GetBuffer();
string base64 = Convert.ToBase64String(bytes);
this.richTextBox.Text = base64;
}
/// <summary>
/// 将Base64字符串转换为图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToImage(object sender, EventArgs e)
{
string base64 = this.richTextBox.Text;
byte[] bytes = Convert.FromBase64String(base64);
MemoryStream memStream = new MemoryStream(bytes);
BinaryFormatter binFormatter = new BinaryFormatter();
Image img = (Image)binFormatter.Deserialize(memStream);
this.pictureBox.Image = img;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询