Exemple #1
0
        private void WritePageDrawBlocks(Image img, HPage page, string sessionName, Rectangle dimension)
        {
            Image himage = img;

            Bitmap   rectCanvas = new Bitmap(himage.Width, himage.Height);
            Graphics grPhoto    = Graphics.FromImage(rectCanvas);

            grPhoto.DrawImage(himage, new System.Drawing.Rectangle(0, 0, rectCanvas.Width, rectCanvas.Height), 0, 0, rectCanvas.Width, rectCanvas.Height,
                              GraphicsUnit.Pixel);
            Graphics bg   = Graphics.FromImage(rectCanvas);
            Pen      bpen = new Pen(Color.Red, 3);
            Pen      rpen = new Pen(Color.Blue, 3);
            Pen      gpen = new Pen(Color.Green, 3);
            Pen      ppen = new Pen(Color.HotPink, 3);


            foreach (HParagraph para in page.Paragraphs)
            {
                bg.DrawRectangle(gpen,
                                 new System.Drawing.Rectangle(new Point((int)para.BBox.Left, (int)para.BBox.Top),
                                                              new Size((int)para.BBox.Width, (int)para.BBox.Height)));

                foreach (HLine line in para.Lines)
                {
                    foreach (HWord word in line.Words)
                    {
                        bg.DrawRectangle(rpen,
                                         new System.Drawing.Rectangle(new Point((int)word.BBox.Left, (int)word.BBox.Top),
                                                                      new Size((int)word.BBox.Width, (int)word.BBox.Height)));
                    }
                    bg.DrawRectangle(bpen,
                                     new System.Drawing.Rectangle(new Point((int)line.BBox.Left, (int)line.BBox.Top),
                                                                  new Size((int)line.BBox.Width, (int)line.BBox.Height)));
                }
            }

            IList <HLine> combinedLines = page.CombineSameRowLines();

            foreach (HLine l in combinedLines.Where(x => x.LineWasCombined))
            {
                bg.DrawRectangle(ppen,
                                 new System.Drawing.Rectangle(new Point((int)l.BBox.Left, (int)l.BBox.Top), new Size((int)l.BBox.Width, (int)l.BBox.Height)));
            }

            AddImage(rectCanvas, sessionName, dimension);
        }