首页 > Windows开发 > 详细

C# winform base64转二进制在页面显示图片

时间:2021-06-11 00:06:22      阅读:61      评论:0      收藏:0      [点我收藏+]
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;
        }
    }
}

 

C# winform base64转二进制在页面显示图片

原文:https://www.cnblogs.com/chenpanpan/p/14872076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!