Error Restoring Signature (Hexadecimal format)

Hi everybody,
  I am problem with restoring data of byte[] type to be loaded on an Ink object. The data was earlier converted to byte[] then finally to hexadecimal data and store on a text file. Is there anyone who can help me solve this problem. Thanks.

Note: The Ink object is from Microsoft.Ink namespace.

Code:

private void LoadXML()
{
  try
  {
    // This object will encode our byte data to a UTF8 string
    UTF8Encoding utf8 = new UTF8Encoding();

    Ink loadedInk = new Ink();

    string filePath = Application.StartupPath + "\\siganture.txt" +

    StreamReader sreader = new StreamReader(filePath);

    string Signature = sreader.ReadToEnd();

    // load the ink into a new ink object
    // once an ink object has been "dirtied" it can never load ink again

    loadedInk.Load(utf8.GetBytes(strSignature));  <- Error Occurs here
   

    // temporarily disable the ink collector and swap ink objects
    ic.Enabled = false;
    ic.Ink = loadedInk;
    ic.Enabled = true;

    // Repaint the inkable region
   
    this.pictureBox.Invalidate();
     

   }
   catch (Exception ex)
   {
       //error handling processes
   }
    }


Error Message:

"System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure\r\n   at Microsoft.Ink.InkDispClass.Load(Object Data)\r\n   at Microsoft.Ink.Ink.Load(Byte[] inkdata)\r\n   at SignatureForm.LoadSiganture() in c:\\....\\signatureform.cs:line 2163\r\n   at signatureForm.btnCancel_Click(Object sender, EventArgs e) in c:\\...\\signatureform.cs:line 705\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button,
Int32 clicks)\r\n   at System.Windows.Forms.Control.WndProc(Message& m)\r\n   at System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n   at System.Windows.Forms.Button.WndProc(Message& m)\r\n   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)\r\n  
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)\r\n   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.
FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.Run(Form mainForm)\r\n   at MainForm.Main() in c:\\....\\mainform.cs:line 557"


den2005



Answer this question

Error Restoring Signature (Hexadecimal format)

  • c&amp;#35; crack

    Hi Den,

    did you try to use FileStream and read byte[] rather than read as string then convert to byte[]

    Try this:

    FileStream fStream = new FileStream(filePath);
    byte[] arOfByte = new byte[fStream.Length];
    fStream.Read(arOfByte, 0, arOfByte.Length];

    loadedInk.Load(arOfByte); 

    blablabla...



  • Sonic1981

    If the data in the file is truly the hex representation of the binary, then that wouldn't help. Instead, assuming the format of the file can't be changed, the original poster needs to read the data in as a string (as he's doing) and convert it from a string into binary data by parsing the hex.

    This can be done relatively simply by considering a pair of characters at a time.

    If the format of the file can be changed to a binary format, then yes - writing the data directly out as binary and then reading it as binary would be simpler. I would suggest a change of filename from ".txt" at that stage though...

    Jon



  • Chris_Botha

    Thanks Jacky. I would try that but right it is put on hold. Thanks Jon for suggestion.


    den2005

  • Error Restoring Signature (Hexadecimal format)