在HTML文件中加载PNG图像

时间:2013-01-10 10:53:46

标签: windows-phone-7 windows-phone-7.1

在我的Windows Phone7.1应用程序Iam从WebBrowser中的本地路径加载HTML文件。为此,我 使用下面的代码将PNG图像转换为base64格式,问题是基本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);

1 个答案:

答案 0 :(得分:0)

如果您没有错误,data包含您的图片,而round1.png中存在htmlcontent,则可能是图片类型错误,请尝试以下操作:

string s = "data:image/png;base64,";