将本地图像从独立存储加载到html页面

将本地图像从独立存储加载到html页面,html,image,windows-phone-7,isolatedstorage,Html,Image,Windows Phone 7,Isolatedstorage,当在来自IsolatedStorage的html页面中使用“图像路径”时,会出现一些奇怪的情况,并与之关联 我想创建一个html页面,该页面将由应用程序的webBrowser对象使用。因此,我在IsolatedStorage中创建了一个html页面,然后将该页面与webbrowser.Navigate一起使用 除了图像,一切都很好 1) 如果我在IsolatedStorage的根目录下创建一个html页面和图像,一切正常,代码正常工作,我可以在页面上看到图像 2) 然而,在我看来,在根目录下保存

当在来自IsolatedStorage的html页面中使用“图像路径”时,会出现一些奇怪的情况,并与之关联

我想创建一个html页面,该页面将由应用程序的webBrowser对象使用。因此,我在IsolatedStorage中创建了一个html页面,然后将该页面与webbrowser.Navigate一起使用

除了图像,一切都很好

1) 如果我在IsolatedStorage的根目录下创建一个html页面和图像,一切正常,代码
正常工作,我可以在页面上看到图像

2) 然而,在我看来,在根目录下保存页面和图像的方式并不是一个好主意,因为我已经有很多目录供应用程序使用,所以,我创建了一个新的目录“Html”,并将所有页面保存在那里

现在,当我打开这个页面时,我看不到我的图像。我已经尝试了src链接的几种变体,但仍然找不到答案


如果层次结构是:

IsolatedStorage-->Html(文件夹)-->index.Html(文件)

(1) IsolatedStorage-->Html(文件夹)-->image.png(文件)

(2) IsolatedStorage-->Html(文件夹)--->图像(文件夹)--->image.png(文件)



事实上,我原以为(1)会有点像
,但我尝试了几个类似的版本,但没有一个有效。

嗯,这似乎有点奇怪:

此方法将图片保存到IsolatedStorage,但不允许在html img标记中使用它:

            using (IsolatedStorageFile isopicsFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isopicsFile.FileExists(Constants.HtmlFolderName + "launch.png") == false)
                {
                    Stream yourFilepath = Application.GetResourceStream(new Uri("/someUri/launch.png", UriKind.Relative)).Stream;

                    BitmapImage b = new BitmapImage();
                    b.SetSource(yourFilepath);

                    WriteableBitmap wb = new WriteableBitmap(b);
                    using (var isoFileStream = isopicsFile.CreateFile(Constants.HtmlFolderName + "launch.png"))
                    {
                        var width = wb.PixelWidth;
                        var height = wb.PixelHeight;
                        // Theoretically, there may be the problem, as the file extention is png, not jpg
                        System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
                    }
                }
            }

这个将保存图片,并允许与html标记一起使用:

            string f = "somePath/launch.png";
            StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
            using (BinaryReader br = new BinaryReader(sr.Stream))
            {
                byte[] data = br.ReadBytes((int)sr.Stream.Length);
                string fileName = "launch.png";
                string filePath = Constants.HtmlFolderName + fileName;

                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (isoStore.FileExists(filePath))
                    {
                        isoStore.DeleteFile(filePath);
                    }

                    using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(filePath)))
                    {
                        bw.Write(data);
                        bw.Close();
                    }
                }
            }
另外,在第二种情况下,图片属性必须设置为Content+Always Copy。

可能的重复