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 : Friday, March 3, 2017 11:23:58 AM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

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

The LEADTOOLS Master Forms Editor uses the DiskMasterForm class by default when saving to disk, which are implementations of the IMasterForm interface.

https://www.leadtools.com/help/leadtools/v20/dh/fa/diskmasterform.html
https://www.leadtools.com/help/leadtools/v20m/dh/fa/imasterform.html

Examples of implementations of these interfaces are installed alongside the SDK. This is the default location of these in the installation folder.
C:\LEADTOOLS 20\Examples\DotNet\CS\AutoMasterFormsRepository

The specific calls to ReadAttributes(), WriteAttributes(), ReadFields(), WriteFields(), ReadForm(), and WriteForm() determine which files get written and read from disk and how they are done so. By default the three files which represent a master form template are a binary file, Xml serialized file, and a Tiff image. This code snippet shows how the Xml serialized file can be base64 encoded such that the text isn't human-readable, and how to obfuscate the image so it doesn't have any discernible information as well, and how to undo these steps when these files are reloaded.

The ScrambleCommand is used in this.
https://www.leadtools.com/help/leadtools/v20/dh/l/imageprocessing-scramblecommand.html

Code:
      private const int KEY_SCRAMBLE = 42;
      // Read the fields of this master form
      public FormPages ReadFields()
      {
         if (!File.Exists(_path + ".txt"))
         {
            return null;
         }

         string text = File.ReadAllText(_path + ".txt");
         byte[] array = Convert.FromBase64String(text);
         MemoryStream ms = new MemoryStream(array);
         _processingEngine.LoadFields(ms);


         //to create new forms pages
         FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();
         FormPages formFields = tempProcessingEngine.Pages;
         formFields.AddRange(_processingEngine.Pages);
         return formFields;
      }
      
      // Update the fields of this master form
      public void WriteFields(FormPages fields)
      {
         MemoryStream ms = new MemoryStream();

         if(fields == null)
            throw new ArgumentNullException("fields");
         _processingEngine.Pages.Clear();
         _processingEngine.Pages.AddRange(fields);
         _processingEngine.SaveFields(ms);

         string text = Convert.ToBase64String(ms.ToArray());

         File.WriteAllText(_path + ".txt", text);
      }

      // Read the form (RasterImage) attached to this master form (optional, might return null)
      public RasterImage ReadForm()
      {
         if(!File.Exists(_path + ".tif"))
            return null;

         RasterImage image = _repository.RasterCodecsInstance.Load(_path + ".tif", 1, CodecsLoadByteOrder.Bgr, 1, -1);

         ImageProcessing.ScrambleCommand sc = new ImageProcessing.ScrambleCommand();
         sc.Rectangle = new LeadRect(0, 0, image.Width, image.Height);

         sc.Key = KEY_SCRAMBLE;
         sc.Flags = ImageProcessing.ScrambleCommandFlags.Decrypt;

         sc.Run(image);

         return image;
      }

      // Update the form (RasterImage) attached to this master form
      public void WriteForm(RasterImage form)
      {
         if(form == null)
            throw new ArgumentNullException("form");
         form.DitheringMethod = RasterDitheringMethod.None;

         ImageProcessing.ScrambleCommand sc = new ImageProcessing.ScrambleCommand();
         sc.Rectangle = new LeadRect(0, 0, form.Width, form.Height);

         sc.Key = KEY_SCRAMBLE;
         sc.Flags = ImageProcessing.ScrambleCommandFlags.Encrypt;

         sc.Run(form);

         _repository.RasterCodecsInstance.Save(form, _path + ".tif", RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite);
      }

The form, as shown in the Master Forms Editor and the obfuscated version saved on disk, are attached.

File Attachment(s):
W4.tif (109kb) downloaded 181 time(s).
File Attachment(s):
SavedMasterForm.tif (458kb) downloaded 180 time(s).

Edited by user Friday, June 1, 2018 10:31:09 AM(UTC)  | Reason: Updating links to v20

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.047 seconds.