Error Restoring Signature (Hexadecimal format)

G

Guest

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
 
J

Jon Skeet [C# MVP]

den 2005 said:
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.

Okay, your problem has nothing to do with ink. It's just converting
between text data and binary data.

You've got binary data which has been hex-encoded. So to get back to
the binary data, you need to *decode* it from hex - currently you're
just getting the string encoded in UTF-8. See
http://www.pobox.com/~skeet/csharp/unicode.html for information about
encodings to understand what's going on.

Now, there's nothing built into the framework (as far as I know) to
decode a whole hex string. If you can change the format of the file, it
would be easier to use Base64 - then you can use Convert.ToBase64String
and Convert.FromBase64String.

Otherwise, just loop through pairs of characters, converting each to a
byte. I'm sure I had some code somewhere on a newsgroup to do this, but
I can't find it right now...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top