Ejemplo n.º 1
0
        public static int GetExamID(Bitmap bitmap)
        {
            var results = QrCodeEncoderDecoder.DecodeMultiple(bitmap);

            if (results != null && results.Length > 0)
            {
                var res = results.FirstOrDefault();
                if (int.TryParse(res.ToString().Split('/')?[0], out int result))
                {
                    return(result);
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            string qrcodeString = string.Join("/",
                                              new string[] {
                _testID.ToString(),
                writer.PageNumber.ToString()
            });

            System.Drawing.Bitmap btm = QrCodeEncoderDecoder.Encode(qrcodeString);
            var pos = writer.GetVerticalPosition(false);


            Image pdfImage = Image.GetInstance(btm, System.Drawing.Imaging.ImageFormat.Jpeg);

            pdfImage.ScaleAbsolute(50f, 50f);
            PdfPTable table = new PdfPTable(3)
            {
                HorizontalAlignment = (Element.ALIGN_CENTER),
                WidthPercentage     = 100
            };

            table.SetWidths(new float[] { 1f, 6f, 1f });

            PdfPCell leftCell = new PdfPCell(pdfImage)
            {
                HorizontalAlignment = Element.ALIGN_LEFT,
                Border = Rectangle.NO_BORDER
            };

            PdfPCell centerCell = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };

            PdfPCell rightCell = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_RIGHT,
                Border = Rectangle.NO_BORDER
            };

            table.AddCell(leftCell);
            table.AddCell(centerCell);
            table.AddCell(rightCell);
            writer.DirectContent.MoveTo(document.Left, 136);
            table.TotalWidth = 595 - (36 + 36);
            table.WriteSelectedRows(0, -1, document.Left, 36 + table.TotalHeight, writer.DirectContent);
        }
Ejemplo n.º 3
0
        public static Bitmap ResizeToStandard(Bitmap bitmap)
        {
            var qrCodesPositions = QrCodeEncoderDecoder.DecodeMultiple(bitmap).ToList().OrderBy(x => x.ResultPoints.FirstOrDefault().Y).Select(x => x.ResultPoints.FirstOrDefault()).ToList();

            if (qrCodesPositions.Count() == 3 && (qrCodesPositions[2].Y - (qrCodesPositions[1].Y + qrCodesPositions[0].Y)) < 0)
            {
                bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
            }

            var qrCodesNewPositions = QrCodeEncoderDecoder.DecodeMultiple(bitmap).ToList().OrderBy(x => x.ResultPoints.FirstOrDefault().X).Select(x => x.ResultPoints).ToList();
            var leftTopQRCode       = qrCodesNewPositions.Take(2).OrderBy(x => x.FirstOrDefault().Y).FirstOrDefault().OrderBy(x => x.X + x.Y).FirstOrDefault();
            var leftBottomQRCode    = qrCodesNewPositions.Take(2).OrderByDescending(x => x.FirstOrDefault().Y).FirstOrDefault().OrderBy(x => x.X).FirstOrDefault();
            var rightTopQRCode      = qrCodesNewPositions[2].OrderByDescending(x => x.X).FirstOrDefault();

            var source = new PointF[4];

            source[0] = new PointF(leftTopQRCode.X, leftTopQRCode.Y);
            source[1] = new PointF(leftBottomQRCode.X, leftBottomQRCode.Y);
            source[2] = new PointF(rightTopQRCode.X, leftBottomQRCode.Y);
            source[3] = new PointF(rightTopQRCode.X, rightTopQRCode.Y);

            var topQRDistance  = rightTopQRCode.X - leftBottomQRCode.X;
            var leftQRDistance = leftBottomQRCode.Y - leftTopQRCode.Y;

            int offsideX   = (int)((topQRDistance / distanceBeetweenTopQRCodes) * standardLeftRightMarginPercentage);
            int offsideTop = (int)((leftQRDistance / distanceBeetweenLeftQRCodes) * standardTopMarginPercentage);
            int offsideBot = (int)((leftQRDistance / distanceBeetweenLeftQRCodes) * standardBottomMarginPercentage);

            source[0] = addOffsideToPoint(source[0], -offsideX, -offsideTop, bitmap);
            source[1] = addOffsideToPoint(source[1], -offsideX, offsideBot, bitmap);
            source[2] = addOffsideToPoint(source[2], offsideX, offsideBot, bitmap);
            source[3] = addOffsideToPoint(source[3], offsideX, -offsideTop, bitmap);

            var target = new PointF[] {
                new PointF(0, 0),
                new PointF(0, standardDocumentHeight),
                new PointF(standardDocumentWidth, standardDocumentHeight),
                new PointF(standardDocumentWidth, 0)
            };

            using (var image = new Image <Gray, byte>(bitmap))
            {
                var tran = CvInvoke.GetPerspectiveTransform(source, target);
                CvInvoke.WarpPerspective(image, image, tran, new Size((int)standardDocumentWidth, (int)standardDocumentHeight));
                return(image.ToBitmap((int)standardDocumentWidth, (int)standardDocumentHeight));
            }
        }
Ejemplo n.º 4
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            string qrcodeString = string.Join("/",
                                              new string[] {
                _testID.ToString(),
                writer.PageNumber.ToString()
            });

            System.Drawing.Bitmap btm = QrCodeEncoderDecoder.Encode(qrcodeString);

            Image pdfImage = Image.GetInstance(btm, System.Drawing.Imaging.ImageFormat.Jpeg);

            pdfImage.ScaleAbsolute(50f, 50f);

            PdfPTable table = new PdfPTable(3)
            {
                HorizontalAlignment = (Element.ALIGN_CENTER),
                WidthPercentage     = 100
            };

            table.SetWidths(new float[] { 1f, 6f, 1f });

            PdfPCell leftCell = new PdfPCell(pdfImage)
            {
                HorizontalAlignment = Element.ALIGN_LEFT,
                Border = Rectangle.NO_BORDER
            };

            PdfPCell centerCell = new PdfPCell(new Paragraph("Exam Name: " + _examName + "\nStudent Name: " + _fullStudentName, _polishFont))
            {
                Border = Rectangle.NO_BORDER
            };

            PdfPCell rightCell = new PdfPCell(pdfImage)
            {
                HorizontalAlignment = Element.ALIGN_RIGHT,
                Border = Rectangle.NO_BORDER
            };

            table.AddCell(leftCell);
            table.AddCell(centerCell);
            table.AddCell(rightCell);
            document.Add(table);
        }