我试图在我的窗口表单中的TIFF图像下插入一个文本水印,肯定会感谢任何人的帮助。我有一个打印按钮,检索图像,缩小它,然后根据我的边距,放置相应的图像打印。我想添加一个额外的部分,在图像打印之前,我添加一个文本水印(在本例中是日期戳),该水印正好在图像下面。
我试过调整页边距,但这只是增加(或减少,取决于数字设置),图像比例,但没有增加额外的空间,我想要添加水印。下面是我到目前为止所拥有的代码:
protected void PrintPage(object sender, PrintPageEventArgs e)
{
if (this.Image == null)
{
e.Cancel = true;
return;
}
//ADD TIME STAMP WATERMARK
string watermark = "DATE ISSUED: " + String.Format("{0:MM/dd/yyyy}", System.DateTime.Now.Date);
System.Drawing.Graphics gpr = Graphics.FromImage(Image);
System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);
Font font = new System.Drawing.Font("Arial", 55, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
SizeF size = e.Graphics.MeasureString(watermark, font);
float x = 0;
float y = Image.Height-size.Height;
RectangleF printArea = new RectangleF(x, y, size.Width, size.Height);
gpr.DrawString(watermark, font, brush, printArea);
e.Graphics.DrawImage(this.Image, e.MarginBounds);
}我在App.config中设置的App.config值包括以下值: Left=70、Right=90、Top=190;Bottom=475。所有的印刷品都将印在字母8,1/2和11大小的纸上。
我可以在图像顶部的任何地方显示水印,但我希望把它放在下面。当我调整y坐标时,它恰好在图像下方,当我打印时,假设它在打印区域之外,因此水印不会打印在页面上(它只显示图像)。
我感谢任何人在这方面的帮助,因为我一直在绞尽脑汁,却没有运气。
发布于 2015-05-22 20:58:06
你不把你的文字印在图像下面吗。我想你想从y=Image.Height + e.MarginBounds.Top和x=e.MarginBounds.Left开始打印
这将打印您的标签左对齐在图像下方的边缘。
更新:这是可行的:
y=-size.Height + e.MarginBounds.Bottom;
x = e.MarginBounds.Left;
e.Graphics.DrawImage(Image, e.MarginBounds);
// note the change. Using e.graphics instead of gpr below
e.Graphics.DrawString(watermark, font, brush, printArea); https://stackoverflow.com/questions/30405119
复制相似问题