图片与Base64的相互转换
图片→Base64:
1 private void button1_Click(object sender, EventArgs e)
2{
3MemoryStream strem = new MemoryStream();
4Image image = new Bitmap(this.pictureBox1.Image);
5image.Save(strem,ImageFormat.Png);
6string strImage = Convert.ToBase64String(strem.ToArray());
7this.textBox1.Text = strImage;
8}
Base64→图片
1 private void button1_Click(object sender, EventArgs e)
2 {
3 string strImage = this.textBox1.Text;
4 Byte[] img = Convert.FromBase64String(strImage);
5 MemoryStream stream = new MemoryStream(img);
6 Image image = new Bitmap(stream);
7 this.pictureBox1.Image = image;
8 }