Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks


Welcome to the Mobile Line Of Business Blog

Tag Cloud


Post Categories




I’ve just been porting a Windows Mobile (.Net CF) application over to the full Net Framework.   I needed to provide a quick way of doing signature capture.

I was pointed by a friend (thanks Ross),  to look at hosting the WPF InkCanvas control on my Windows Forms, form.   I just dropped a Panel (Panel1) on my form and used the following code -

 System.Windows.Controls.InkCanvas inkbox = null;
        public frmpleasesign()
            inkbox = new System.Windows.Controls.InkCanvas();
            inkbox.Name = "myinbox";
            ElementHost elementHost = new ElementHost();
            elementHost.Dock = DockStyle.None;
            elementHost.Width = panel1.Width;
            elementHost.Height = panel1.Height;
            elementHost.Child = inkbox;


To save the signature out to a byte array, that can be saved to my database I used, the following code -


 public static byte[] SignatureToBitmapBytes(InkCanvas icSignature)
            int margin = (int)icSignature.Margin.Left;
            int width = (int)icSignature.ActualWidth - margin;
            int height = (int)icSignature.ActualHeight - margin;
            //render ink to bitmap 
            RenderTargetBitmap rtb =
            new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
           byte[] bitmapBytes;
            using (MemoryStream ms = new MemoryStream())
                ms.Position = 0;
               bitmapBytes = ms.ToArray(); 
            return bitmapBytes;
Technorati Tags: ,
posted on Tuesday, July 28, 2009 8:34 AM