Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, June 7, 2017 12:48:07 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

Was thanked: 9 time(s) in 9 post(s)

Sometimes, when creating a master form template, a blank copy of a form can be inaccessible. However, it's recommended to use blank forms when creating templates to prevent the forms engine from improperly identifying the filled-in information on the forms as unique attributes. This code snippet shows how a master form which has been filled in can be blanked out by replacing the contents of the form fields with a solid color. As most forms are binarized into black text on a white backdrop, this changes the blanked out fields to be white as well.

The parameters passed in are the path to the image file (in tif format) of the master form image, and the xmlFile describing where the form field locations are. Note it may be necessary to regenerate the BIN file after performing this to accommodate changes to the form from which the unique attributes are determined.
Code:

public static void BlankFilledForm(string imageFile, string xmlFile)
      {
         using (RasterCodecs codecs = new RasterCodecs())
         {
            FormProcessingEngine engine = new FormProcessingEngine();
            engine.LoadFields(xmlFile);
            FormPages formFields = engine.Pages;

            RasterImage image = codecs.Load(imageFile, 0, CodecsLoadByteOrder.Bgr, 1, -1);

            for (int i = 0; i < image.PageCount; i++)
            {
               image.Page = i + 1;

               FormPage page = formFields[0];

               LogicalRectangle rr = page[0].Bounds;
               LeadRect lr = rr.ToRectangle(image.GetImageWidthDpi(true), image.GetImageHeightDpi(true));
               image.SetRegion(null, new RasterRegion(lr), RasterRegionCombineMode.Set);

               for (int j = 1; j < page.Count; j++)
               {
                  rr = page[j].Bounds;
                  lr = rr.ToRectangle(image.GetImageWidthDpi(true), image.GetImageHeightDpi(true));
                  image.SetRegion(null, new RasterRegion(lr), RasterRegionCombineMode.Or);
               }

               FillCommand fc = new FillCommand();
               fc.Color = RasterColor.White;
               fc.Run(image);

               image.MakeRegionEmpty();
            }

            codecs.Save(image, "blank-" + imageFile, image.OriginalFormat, image.BitsPerPixel);
         }
      }


This utilizes the LEADTOOLS FillCommand and image regions. For more information on how the FillCommand is used and how the different regions are set, see our documentation on the command and the enumeration.

https://www.leadtools.com/help/leadtools/v19m/dh/l/imageprocessing-fillcommand.html
https://www.leadtools.com/help/leadtools/v19m/dh/l/rasterregioncombinemode.html
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.043 seconds.