大佬教程收集整理的这篇文章主要介绍了windows-8 – Windows 8 RT – 动态生成html不会渲染图像,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
特别是,当文件路径引用LocalState目录时,尝试启动网页时似乎存在安全问题.
当我右键单击html文件并在Visual studio中的浏览器中查看时,网页会加载图像.
我已将src标记的路径更改为:src =“ms-apPDAta:///Local/@L_944_4@.jpeg”
它不起作用.
帮我…
示例代码
public static async Task update(WebView webview,IStorageFile filE) { var html = await Windows.Storage.PathIO.ReadTextAsync(file.Path); webview.NavigateToString(html); }
服务器上的图像
一种解决方案是将源更改为指向网络服务器而不是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); }
以上是大佬教程为你收集整理的windows-8 – Windows 8 RT – 动态生成html不会渲染图像全部内容,希望文章能够帮你解决windows-8 – Windows 8 RT – 动态生成html不会渲染图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。