使用自定义的IMasterForm模糊表单模板数据
默认情况下,LEADTOOLS主窗体编辑器使用DiskMasterForm类保存到磁盘,这是IMasterForm界面的实现。https://www.leadtools.com/help/leadtools/v19m/dh/fa/diskmasterform.html
https://www.leadtools.com/help/leadtools/v19m/dh/fa/imasterform.html
这些接口的实现示例与SDK一起安装。这是安装文件夹中这些的默认位置。
C:\ LEADTOOLS 19 \ Examples \ DotNet \ CS \ AutoMasterFormsRepository
对ReadAttributes(),WriteAttributes(),ReadFields(),WriteFields(),ReadForm()和WriteForm())的特定调用决定了哪些文件从磁盘写入和读取,以及它们如何完成。默认情况下,表示主表单模板的三个文件是二进制文件,Xml序列化文件和Tiff映像。此代码段显示了Xml序列化文件如何进行base64编码,以使文本不可读取,以及如何混淆图像,因此它还没有任何可辨别的信息,以及如何撤消这些步骤,当这些文件被重新加载。
这里使用了ScrambleCommand。
https://www.leadtools.com/help/leadtools/v19m/dh/l/imageprocessing-scramblecommand.html
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);
}
附件是主窗体编辑器中显示的形式和保存在磁盘上的混淆版本。
页:
[1]