我想用C#winforms生成並輸出帶有圖像的html文件。資源文件夾中有幾張圖片,但我無法將它們輸出到html。如何訪問和輸出C#中的資源中的圖像到html代碼?
任何人都可以建議如何訪問和輸出資源中的圖像到HTML文件?
我的代碼:
從故事using System;
using System.Windows.Forms;
using System.IO;
namespace winformToHtml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_report_Click(object sender, EventArgs e)
{
StreamWriter sWrite = new StreamWriter("C:\\report.html");
sWrite.WriteLine("<html>");
sWrite.WriteLine("<body>");
sWrite.WriteLine("<p> <img src= 'Resources/image.png' height='10%' width='5%' > </p>");
sWrite.WriteLine("<body>");
sWrite.WriteLine("<html>");
sWrite.Close();
}
}
}
我得到一個錯誤在該行image.Save(圖像,ImageFormat.Jpeg) ;我認爲它應該是image.Save(m,ImageFormat.Jpeg);和Base64Encoded(Resource.Image)是Base64Encoded(Resources.Image)? – harishli2020
是的,它應該我米。我做了編輯。 – Ksv3n
當我將圖像導出爲html時,底部圖像的某些部分缺失。你能否建議我如何解決這個問題? – harishli2020