我正在尝试制作一个程序,将图像文件打印到打印机上 A4 大小的纸上。(图像缩放到 A4)这是我目前正在使用的代码。
Function.cs
Image tmp;
public void PrintImage(string FileName)
{
tmp = Image.FromFile(FileName);
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "My Print Document";
printDoc.PrintPage += new PrintPageEventHandler(OnPrintPage);
// Send print message
Console.WriteLine("Sending Print Message...");
try
{
printDoc.Print();
}
catch(Exception)
{
Console.WriteLine("Error: No Printer Installed");
}
//
// Event Handler
//
}
private void OnPrintPage(object sender, PrintPageEventArgs ppea)
{
Console.WriteLine("Printing...");
Graphics g = ppea.Graphics;
g.DrawImage(tmp,0,0);
}
Main.cs
string ReceiptFilePath = "C:\\Receipt.jpg"; // The Image I want to print.
private void button1_Click(object sender, EventArgs e)
{
functions.PrintImage(ReceiptFilePath);
}
使用上面的代码,它可以打印,但它不是 A4 大小,而是放大了近 400%。我应该如何修改代码?