using System; using System.Drawing; using System.IO; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string base64String = "";//base64 //截取base64逗号之后的字符串 string strbase64 = base64String.Trim().Substring(base64String.IndexOf(",") + 1); //base64转二进制 byte[] bytes = Convert.FromBase64String(strbase64); MemoryStream memStream = new MemoryStream(bytes); #region 方法一 //this.pictureBox1.Image = Image.FromStream(memStream); #endregion #region 方法二 Bitmap bmpt = new Bitmap(memStream); this.pictureBox1.Image = bmpt; #endregion //PictureBox 图片自适应 this.pictureBox1.BackgroundImageLayout = ImageLayout.Stretch; this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; } } }
原文:https://www.cnblogs.com/chenpanpan/p/14872076.html