| Re: Saving / Loading Ink Data
Ok, now I have another problem. The control works as I would like it,
but I want to be able to interact with it using Javascript (to read
the Base64String from the inkPicture, save to a html field, and vice-
versa).
The saving from the control works fine - the string enters a textbox
on the html page. But if I try and put the data back into the control
it behaves strangely:
1) If I don't clear the ink from the control first, then no error
occurs. It seems to work normally.
2) If I clear the ink first, then I get : "Catastrophic failure
(Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED) "
To test what was going on, I added a textbox inside the control. I
then got the control to try to reload the ink from this textbox. Once
I had the Base64String in the html textbox, I pasted it into the new
control based textbox, and everything worked fine. Could there be
some problem with Javascript which is not loading the data back
correctly?
Anyway, my code is:
public string Value
{
get
{return (GetBase64ISF()); }
set
{
try
{
byte[] inkBytes = Convert.FromBase64String(Value);
inkPicture1.InkEnabled = false;
inkPicture1.Ink = new Microsoft.Ink.Ink();
inkPicture1.Ink.Load(inkBytes);
inkPicture1.InkEnabled = true;
inkPicture1.Invalidate();
}
catch (Exception e)
{ TextBox1.Text = e.Message + "\r\n" ; };
}
}
private string GetBase64ISF()
{
byte[] inkBytes =
inkPicture1.Ink.Save(PersistenceFormat.Gif);
return Convert.ToBase64String(inkBytes);
}
public void clear()
{
inkPicture1.Ink.DeleteStrokes();
inkPicture1.Refresh();
}
and the html / javascript is:
<script>
function getValue()
{document.frmCheckMe.elements["thetext"].value =
document.frmCheckMe.elements["PICTURE"].value;}
function setValue()
{document.frmCheckMe.elements["PICTURE"].value =
document.frmCheckMe.elements["thetext"].value;}
</script>
<form name='frmCheckMe' id='frmCheckMe'>
<object id='PICTURE' name='PICTURE'
classid="PC1.dll#PC1.UserControl1">
</object>
<input type="button" value="Save" onClick="getValue();"/>
<input type="button" value="Load" onClick="setValue();"/>
<input type="button" value="Wipe"
onClick="document.frmCheckMe.elements["PICTURE"].clear();"/>
<textarea style='width:835px;font-size:18px;' id = 'thetext'
name='thetext' cols='70'></textarea>
</form> |