首页 > 代码库 > C# 图片与Base64互转
C# 图片与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; }
C# 图片与Base64互转
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。