首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Visual Studio中打包和部署时添加图像资源时,图像资源的文件路径是什么?

在Visual Studio中打包和部署时添加图像资源时,图像资源的文件路径是什么?
EN

Stack Overflow用户
提问于 2021-10-04 21:35:40
回答 1查看 23关注 0票数 0

我已经创建了一个html文件,它为我的C#应用程序输出收据。在html报告中,我在收据的顶部有一个徽标。该映像位于debug文件夹中,当我运行它进行调试时,它工作得很好。

然而,当我打包和部署我的应用程序时,回执丢失了图像。在打包和部署时,我将映像添加为资源,这样我就知道它在那里。我假设我需要放入访问镜像的完整路径。

但是,当我们打包和部署时,我不知道路径是什么。我们打包和部署时添加的镜像资源在哪里?安装应用程序时存储在哪里?

下面是创建html文件的函数。我把图像源放在哪里,当我调试和打包和部署时,我需要放什么才能让徽标显示出来?

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

发布于 2021-10-04 23:06:58

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

您可以使用this等在线服务将徽标转换为Base64字符串

然后以这种方式将其添加到HTML输出中

代码语言:javascript
复制
<img src="data:image/png;base64,#past here your image encoded text#">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69442647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档