我想使用 C# 将大图像显示为一个小矩形。问题是当我不调整矩形大小和图像时,每次只显示一半的图像。有没有办法在定义的范围内完全打印图像?我的意思是图像可以将自身重新调整为矩形大小吗?
以下是我的代码:
int imagePrintHeight = this.PaperSize.Width - this.PrintMargins.Top - this.PrintMargins.Bottom;
int imagePrintWidth = this.PaperSize.Height - this.PrintMargins.Left - this.PrintMargins.Right;
Size DatestoPrintSize = TextRenderer.MeasureText(DatestoPrint, new Font(this.Font.FontFamily, 10));
y = y + descriptionSize.Height + DatestoPrintSize.Height;
imagePrintHeight = imagePrintHeight - descriptionSize.Height - DatestoPrintSize.Height;
e.Graphics.DrawString(objCurrentPrintJob.sDescription, new Font(this.Font.FontFamily, 10), new SolidBrush(Color.Black), x + (imagePrintWidth - descriptionSize.Width) / 2, this.PrintMargins.Top);
e.Graphics.DrawString(DatestoPrint, new Font(this.Font.FontFamily, 10), new SolidBrush(Color.Black), x + (imagePrintWidth - DatestoPrintSize.Width) / 2, this.PrintMargins.Top + descriptionSize.Height);
}
decimal ratio = Math.Round(decimal.Divide(imagetoPrint.Width, imagetoPrint.Height), 4);
int tempimagePrintWidth = (int)(Math.Round(imagePrintHeight * ratio, 4));
x += (int)((imagePrintWidth - tempimagePrintWidth) / 2);
要打印我使用以下
e.Graphics.DrawImage(imagetoPrint, new Rectangle(x,y ,tempimagePrintWidth,imagePrintHeight));