byte或Stream转化成图片

 <img src="/QRCode/index" alt="二维码" style="width:150px; height:150px;" />
 public ActionResult Index()
        {
            Stream stream = null;
            byte[] byteData = null;
            string userId = Convert.ToString(System.Web.HttpContext.Current.Session["yuan_userid"]);
            var userModel = ServiceLocator.Create<EnYuan.BSS.User.IUserService>().GetUser(userId);
            string userName = "";
            if (userModel != null)
                userName = userModel.Name;
            try
            {
                var model = QRCodeImgDao.Instance.GetModel(userId);
                if (model == null)
                {
                    //生成记录
                    QRCodeImgModel QRmodel = new QRCodeImgModel();
                    QRmodel.UserId = userId;
                    //自动增量
                    QRmodel.QudaoId = QRCodeImgDao.Instance.AutoAddId();
                    #region 生成图片
                    string UrlImg = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + QRCode_WxHelper.CreateQRCode(QRmodel.QudaoId);
                    WebClient webClient = new WebClient();
                    webClient.Credentials = CredentialCache.DefaultCredentials;
                    //以数组的形式下载指定文件
                     byteData = webClient.DownloadData(UrlImg);
                    //stream = BytesToStream(byteData);
                    #endregion
                   
                }
                 else
                { 
                    if (!string.IsNullOrEmpty(model.QRCodeImg))
                    {
                        byteData = System.Convert.FromBase64String(model.QRCodeImg); 
                    } 
                }
                
            }
            catch { }
            return File(byteData, "image/jpeg");  
        }


你可能感兴趣的:(Stream,byte,转化为图片)