windows-8 – Windows 8 RT – 动态生成html不会渲染图像
发布时间:2020-12-14 02:49:50 所属栏目:Windows 来源:网络整理
导读:在LocalState目录中,我无法在网页上加载图像. 特别是,当文件路径引用LocalState目录时,尝试启动网页时似乎存在安全问题. 当我右键单击html文件并在Visual Studio中的浏览器中查看时,网页会加载图像. 我已将src标记的路径更改为:src =“ms-appdata:///Local
在LocalState目录中,我无法在网页上加载图像.
特别是,当文件路径引用LocalState目录时,尝试启动网页时似乎存在安全问题. 当我右键单击html文件并在Visual Studio中的浏览器中查看时,网页会加载图像. 我已将src标记的路径更改为:src =“ms-appdata:///Local/Logo.jpeg” 帮我… 示例代码 public static async Task Update(WebView webview,IStorageFile file) { var html = await Windows.Storage.PathIO.ReadTextAsync(file.Path); webview.NavigateToString(html); } 解决方法
NavigateToString方法不适用于指向LocalData文件夹中的图像的标记. (据我所知,无论如何).实际上NavigateToString也会破坏JavaScript和CSS链接.
服务器上的图像 一种解决方案是将源更改为指向网络服务器而不是localdata.我不确定它是否适用于您的应用场景. 图像和HTML作为内容 第二种选择是将您的html和图像文件作为内容添加到您的应用程序并使用 WebView1.Navigate(new Uri("ms-appx-web:///assets/SampleHtmlPage.html")); 加载HTML. 在进程HTTP服务器中 这是一个在应用程序中使用自定义HTTP服务器来处理问题的解决方案. Loading Local HTML Content in Metro WebView (Windows 8) 基础64编码图像 最后,还有另一种解决方案,使用LocalData文件夹中的图像的Base64编码. internal async void MakeHtmlString() { StorageFile imageFile; // get image file here. var html = string.Format("<div><img src='data:image/png;base64,{0}'",await GetImageBase64(imageFile)); } internal async Task<string> GetImageBase64(StorageFile imageFile) { var imageStream = await imageFile.OpenAsync(FileAccessMode.Read); var inputStream = imageStream.GetInputStreamAt(0); var dataReader = new DataReader(inputStream); var dataResults = await dataReader.LoadAsync((uint)imageStream.Size); var bytes = new byte[dataResults]; dataReader.ReadBytes(bytes); return Convert.ToBase64String(bytes); } 最后一种方法适用于图像,但不适用于CSS文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- microsoft-edge – 如何在Edge Browser中通过Reg
- Window Server配置Flask
- Windows:复制正在编写的文件?
- windows – 使用新的HD(HP DL380 G3)扩展Raid5
- Windows – 微软仍然支持WIN吗?
- office365 – Microsoft Graph:在一个请求中列出
- windows-server-2008-r2 – 找出Windows远程桌面
- Windows – 事件ID 9331 MSExchangeSA和事件ID 9
- DOS批处理中%cd%和%~dp0的区别
- active-directory – Windows 10上的Active Dire
热点阅读