0

Currently i have this method that draws a rectangle on the top left corner of the page. I wanted to create another method that will search for a rectangle drawing in any of the four corners of my scanned document. How can i go about writing a method that will check each corner for a rectangle drawing based what i created for drawing the rectangle.

static void AddQRTag(PdfSharp.Drawing.XGraphics gfx, int xPosition, int yPosition, string QRdata, string HRdata)
    {
        gfx.DrawRectangle(XBrushes.White, xPosition, yPosition, xPosition + 55, yPosition + 85);

        PdfSharp.Drawing.XImage xImage =
            PdfSharp.Drawing.XImage.FromGdiPlusImage(BuildQR(QRdata.ToUpper(), 3,
                                            QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC, 2, QRCodeEncoder.ERROR_CORRECTION.M));
        gfx.DrawImage(xImage, xPosition + 5, yPosition + 5, xImage.PixelWidth * .8, xImage.PixelWidth * .8);


        //XFont font = new XFont("OCR B", 10, XFontStyle.Bold);
        XFont font = new XFont("OCR B", 6);
        XTextFormatter tf = new XTextFormatter(gfx);
        tf.Alignment = XParagraphAlignment.Left;

        //XStringFormat format = new XStringFormat();
        //format.Alignment = XStringAlignment.Near;
        XRect layout = new XRect(xPosition + 5, yPosition + 55, 55, 30);
        tf.DrawString(HRdata.ToUpper(), font, XBrushes.Black, layout, XStringFormats.TopLeft);
        //gfx.DrawString(HRdata, font, XBrushes.Black,layout,format);
    }
4

1 回答 1

0

可能有许多技术可以使用 3rd 方 pdf 阅读器 API 在 PDF 文件中查找图像。但是假设您找不到任何方法,并且假设您可以阅读 pdf 文件并将它们转换为简单的图像,您可以使用图像处理技术很容易地找到您的矩形。

最简单(且稳健)的事情是使用简单的相关器来查找您的矩形,如果您不知道正方形的尺寸,您可以使用不同的矩形运行相关器几次。

如果您需要高性能,还有其他解决方案(如果是这种情况,只需写评论,我会为您指出另一个方向)

于 2013-03-01T14:51:02.553 回答