Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在图像下方添加水印,但在C中的打印区域内#_C#_Winforms_Image Processing_Printing_Watermark - Fatal编程技术网

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

C# 在图像下方添加水印,但在C中的打印区域内#,c#,winforms,image-processing,printing,watermark,C#,Winforms,Image Processing,Printing,Watermark,我正在尝试在我的windows窗体中的TIFF图像下插入一个文本水印,非常感谢任何人的帮助。我有一个打印按钮,可以检索图像,缩小它的比例,然后根据我的边距,相应地放置图像进行打印。我想添加一个额外的部分,在图像打印之前,我在图像下方添加一个文本水印(在本例中是一个日期戳) 我尝试过调整边距,但这只会增加(或减少,取决于数字设置)图像比例,但不会添加我想要添加水印的额外房间。以下是我到目前为止的代码: protected void PrintPage(object sender, Prin

我正在尝试在我的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。所有打印输出都将以肖像风格打印在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);  

是的,我正在尝试打印图像下方的文本。我会试试你的建议。谢谢。我是说实际上在下面(后面)。除非你的图像是透明的,否则它不会让文本显示出来。打印图像后尝试添加文本图像不透明。我尝试了你的建议,但是没有成功(在打印件上找不到水印)。我不相信我已经尝试过在图像打印后添加文本。值得一试……我也试着在图像打印后放置文本,但是,文本在打印页面上找不到(出于测试目的,使用x=0和y=0的坐标)。我仍在寻找一种方法来实现这一点…只是想补充一点,我尝试了上述建议,但没有成功地尝试让它工作并在.TIFF图像下显示水印。