页面转cavas,图片跨域问题
前台img,src地址为http://...............此时可正常显示
当整个页面转Cavas时,此时图片会产生跨域问题
解决方案:后台请求图片,转为base64,给前台绑定
//获取图片并转为base64 private string Base64(string imgUrl) { WebRequest webRequest = WebRequest.Create(imgUrl); WebResponse webResponse = webRequest.GetResponse(); Bitmap myImage = new Bitmap(webResponse.GetResponseStream()); MemoryStream ms = new MemoryStream(); myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return Convert.ToBase64String(ms.ToArray()); }
转好后,需进一步处理
url = "data:image/png;base64," + Base64(url);
必须加上 data:image/png;base64,