Network SDK for Java - Simple image rendering

In the first example/application, we showed you how to get the data from the pen and save it to disk as a PGC file. Now when the pen data has been saved, we can continue processing it further. The most common step is to render the data on the background image produced by the FDT. In this example, we will show you how you can build a simple application that renders the strokes on the background image.
The pre-conditions to run this project are that the PGC file is saved in the current folder together with the background image and the PAD file is registered in the PAD folder.

In the following example, an image is rendered (for each page, if several). The steps to do are the following:

  • Read the PGC file and initialize the pen data
  • Load the background image
  • Set the rendering scale to reflect the resolution of the background
  • Draw strokes on the background
  • Save the rendered image

To improve the functionality, it is for example possible to build a polling function that scans the folder for new PGC files and starts the application. Then, as soon as a new PGC file is created, the application picks up the file, loads the background image, draws the strokes in the PGC file on the background image and finally, saves the new image. In this example, the background image is pointed out directly but it is also possible to parse the PAD file to find what background image to load for a specific pattern page.

<span class="wysiwyg-font-size-small">using System;  using System.Drawing;  using System.Drawing.Imaging;    using Anoto.Service;  using Anoto.StrokeRenderer;  using Anoto.Util;  using Anoto.Common;      namespace PCSDKStart  {     class PGCRenderer     {        //Define paths to files and application name        private static string BASE_PATH = Environment.CurrentDirectory+"\\";        private static string BG_IMAGE = BASE_PATH + "Demo_copied_pattern_1_200.png";        private static string PGC_FILE = BASE_PATH + "18-02-2008_14.48.41.1512.pgc";                static void Main(string[] args)        {           try           {              PenRequest request = new PenRequest();              File file = new File();              Renderer renderer = new Renderer();              Image img = null;                            //read the pgc file and initialize the pen data              Object data = file.Read(PGC_FILE);              request.Initialize(data);                            foreach (Page page in request.Pages)              {                 img = Image.FromFile(BG_IMAGE);                 renderer.ObjectTransform.Reset();                 renderer.ObjectTransform.Scale(img.HorizontalResolution / Anoto.StrokeRenderer.Renderer.AnotoDpi,                 img.VerticalResolution / Anoto.StrokeRenderer.Renderer.AnotoDpi);                 renderer.Draw(img, page);                 img.Save(BASE_PATH + page.PageAddress + ".png", ImageFormat.Png);              }           }           catch (Exception e)           {              //something went wrong...take care of it              Console.WriteLine(e);              Console.ReadLine();           }        }     }  } </span>

TIP: See the Net class “FileSystemWatcher” as a polling alternative. This is an interesting class offering monitoring functionality for your file system. This means that you can monitor a directory for file changes (like file creation, modification, etc.) and subscribe to different events based on predefined filters.

Click here to download a zip file containing source code, etc. for this example.

Still need help? Contact Us Contact Us