繁体   English   中英

package中添加图片资源并部署到Visual Studio中时,图片资源的文件路径是什么?

[英]What is the file path for image resources when you add them during package and deploy in Visual Studio?

我制作了一个 html 文件,输出了我的 C# 申请的收据。 在 html 报告中,我在收据顶部有一个徽标。 该图像位于调试文件夹中,当我运行它进行调试时它工作正常。

但是,当我 package 并部署我的应用程序时,收据丢失了图像。 我在 package 和部署时将图像添加为资源,所以我知道它在那里。 我假设我需要输入完整路径才能访问图像。

但是,我不知道我们 package 和部署时的路径是什么。 我们package时添加的图片资源和安装应用时deploy存储的图片资源在哪里?

这是我的 function,它创建了我的 html 文件。 我把图像源放在哪里,我需要放什么才能在我调试和部署 package 时显示徽标?

private StringBuilder GenerateReport()
{
    StringBuilder html = new StringBuilder();
    StringBuilder css = new StringBuilder();
    try
    {
        // CSS is a way to style the HTML page. Each HTML tag can be customized.
        // In this example, the H1 and TD tags are customized.
        // Refer to this website for examples: https://www.w3schools.com/Css/css_syntax.asp

        css.AppendLine("<style>");
        css.AppendLine("td {padding: 5px; text-align:center; font-weight: bold; text-align: center; font-size: 12px;}");
        css.AppendLine("h1 {color: orange;}");
        css.AppendLine("</style>");

        // HTML is used to format the layout of a webpage. This will be the frame
        // we use to place our data in. CSS is used to style the page to look a
        // certain way.

        // The <HTML> and </HTML> tags are the start and end of a webpage.
        // The <HEAD> and </HEAD> tags gives information about the webpage
        // such as the title and if there is any CSS styles being used.
        // The text between the <TITLE> and </TITLE> tags are used by the
        // browser to display the name of the page.
        // <BODY> and </BODY> is where the data of the page is stored
        // <H1> and </H1> is the largest font size for headings. These
        // can be from H1 to H6. H6 is the smallest font. https://www.w3schools.com/tags/tag_hn.asp

        html.AppendLine("<html>");
        css.AppendLine("<center {display: block;margin - left: auto;margin - right: auto;width: 50 %;}</center>");
        html.AppendLine($"<head>{css}<title>{"Receipt"}</title></head>");
        //css.AppendLine("<left {display: block;margin - left: auto;margin - right: auto;width: 50 %;}</left>");
        html.Append("<img src= Debug\\hunting.jpg style=' align: center; width: 75px; height: 50px;'>");
        html.AppendLine("<body>");

        html.AppendLine($"<h1>{" Order Receipt"}</h1>");
        html.Append($"<br></br>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 15px'><b>{"Customer: " + strFirstName + " " + strLastName}</b></p>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 15px'><b>{"Order Number: " + strMaxOrderID}</b></p>");
        html.Append($"<p style = 'text-indent: -550px; font-size: 10px'><b>{"Phone Number: " + strPhoneNumber}</b></p>");
        // Create table of data
        // <TABLE> and </TABLE> is the start and end of a table of rows and data.
        // <TR> and </TR> is one row of data. They contain <TD> and </TD> tags.
        // <TD> and </TD> represents the data inside of the table in a particular row.
        // https://www.w3schools.com/tags/tag_table.asp

        // I used an <HR /> tag which is a "horizontal rule" as table data.
        // You can "span" it across multiple columns of data.

        html.AppendLine("<table>");
        html.AppendLine("<tr><td>Item Name</td><td>Quantity</td><td>Price</td></tr>");
        html.AppendLine("<tr><td colspan=3><hr /></td></tr>");
        for (int i = 0; i < lstShoppingCartName.Count; i++)
        {
            html.Append("<tr>");
            html.Append($"<td>{lstShoppingCartName[i]}</td>");
            html.Append($"<td>{lstShoppingCartQuantity[i]}</td>");
            html.Append($"<td>{lstShoppingCartCost[i]}</td>");
            html.Append("</tr>");
            html.AppendLine("<tr><td colspan=4><hr /></td></tr>");
        }
        html.AppendLine("</table>");
        html.Append($"<br></br><br></br>");
        html.Append($"<p style = 'align:center; text-indent: 390px; font-size: 15px '><b>{"SubTotal: " + decSubTotal.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 371px; font-size: 15px '><b>{"Discount Percent: " + decDiscountPercent.ToString("N3")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 422px; font-size: 15px '><b>{"Discount: " + decDiscount.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 297px; font-size: 15px '><b>{"SubTotal After Discount: " + decSubTotalDiscount.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 430px; font-size: 15px '><b>{"Taxes: " + decTaxes.ToString("C2")}</b></p>");
        html.Append($"<p style = 'align:center; text-indent: 450px; font-size: 20px ' ><b>{"Total: " + decTotal.ToString("C2")}</b></p>");
        html.Append($"<div><button onClick='window.print()'> {"Print this page"}</ button ></ div >");
        html.AppendLine("</body></html>");
    }
    catch(Exception ex)
    {
        MessageBox.Show(message + ex.Message, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    return html; // The returned value has all the HTML and CSS code to represent a webpage
}

如果您的徽标不是一个巨大的图像文件,您可以使用 Base64 编码将其直接设置到标记中,将图像转换为字符串,以代替路径使用。

您可以使用这样的在线服务将徽标转换为 Base64 字符串

然后通过这种方式将其添加到您的 HTML output

<img src="data:image/png;base64,#past here your image encoded text#">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM