By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,663 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,663 IT Pros & Developers. It's quick & easy.

Error Restoring Signature (Hexadecimal format)

P: n/a
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(MouseEventAr gs 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(M essage& m)\r\n at
System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)\r\n at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)\r\n at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at
System.Windows.Forms.ThreadContext.RunMessageLoopI nner(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
--
MCP Year 2005, Philippines
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
den 2005 <de*****@discussions.microsoft.com> wrote:
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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.