0

在我的 Windows Phone7.1 应用程序中,我正在从 WebBrowser 的本地路径加载 HTML 文件。为此,我
使用以下代码将 PNG 图像转换为 base64 格式,问题是图像路径的 base 64 格式未在 webbrowser 中加载图像。请帮助我在哪里犯了错误?

string s = "data:image/jpg;base64,";
imgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewUIChanges.Htmlfile.round1.png");
        byte[] data = new byte[(int)imgStream.Length];
        int offset = 0;
        while (offset < data.Length)
        {
            int bytesRead = imgStream.Read(data, offset, data.Length - offset);
            if (bytesRead <= 0)
            {
                throw new EndOfStreamException("Stream wasn't as long as it claimed");
            }
            offset += bytesRead;
        }
        base64 = Convert.ToBase64String(data);

        Stream htmlStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewUIChanges.Htmlfile.equity_built.html");
        StreamReader reader = new StreamReader(htmlStream);
        string htmlcontent = reader.ReadToEnd();
        htmlcontent = htmlcontent.Replace("round1.png", s + base64);


        wb.NavigateToString(htmlcontent);
4

1 回答 1

0

如果您没有错误,data包含您的图像,并且round1.png存在于 中htmlcontent,那么它可能只是图像类型错误,试试这个:

string s = "data:image/png;base64,";
于 2013-01-10T16:49:43.847 回答