图片与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 }
posted @ 2011-06-22 15:35  王元勋  阅读(510)  评论(2编辑  收藏  举报