gpt4 book ai didi

c# - 在图像下方但在 C# 的打印区域内添加水印

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:35 24 4
gpt4 key购买 nike

我正在尝试在我的 Windows 窗体中的 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 中设置的 e.MarginBounds 的值包括以下值:Left=70,Right=90,Top=190;底部=475。所有打印输出都将以纵向样式打印在 Letter 8 1/2 x 11 尺寸的纸张上。

我可以在图像顶部的任何位置显示水印,但我希望将它放在下面。当我调整 y 坐标时,它恰好在图像下方,当我打印时,我假设它在打印区域之外,因此水印不会打印在页面上(它只显示图像)。

我很感激任何人在这方面的帮助,因为我一直在绞尽脑汁,但没有运气。

最佳答案

您不是在图像下方打印文字吗?我想你想在 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);

关于c# - 在图像下方但在 C# 的打印区域内添加水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30405119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com