|
| | |||||||
| Tablet PC Developers Show off your work while discussing with others how to create ink enabled applications. |
| | LinkBack | Thread Tools |
| |||
| Saving / Loading Ink Data I am trying to follow the example on: http://msdn2.microsoft.com/en-us/library/aa480684.aspx And have created a simple control - 1 InkPicture 1 TextBox 3 Buttons The code for the buttons are: private void button2_Click(object sender, EventArgs e) { inkPicture1.Ink.DeleteStrokes(); inkPicture1.Refresh(); } private void button1_Click(object sender, EventArgs e) { byte[] inkBytes = inkPicture1.Ink.Save(PersistenceFormat.Gif); textBox1.Text = Convert.ToBase64String(inkBytes); } private void button3_Click(object sender, EventArgs e) { byte[] inkBytes = Convert.FromBase64String(textBox1.Text); inkPicture1.Ink.Load(inkBytes); inkPicture1.Invalidate(); } So what I am trying to acheive is 1) Draw some ink on the inkpicture 2) Click on button1 and store the ink as a Base64String somewhere (textBox1.Text) 3) Click on button2 to clear the page 4) Click on button3 to restore the ink back ot the ink control Stage 2 seems to work - populates the textbox with a string Stage 3 is fine - clears the picture Stage 4 when I try to load the ink fails ("Value does not fall within the specified range") What am I doing wrong? |
| |||
| Re: Saving / Loading Ink Data I got it - private void button3_Click(object sender, EventArgs e) { byte[] inkBytes = Convert.FromBase64String(textBox1.Text); inkPicture1.InkEnabled = false; inkPicture1.Ink = new Microsoft.Ink.Ink(); inkPicture1.Ink.Load(inkBytes); inkPicture1.InkEnabled = true; inkPicture1.Invalidate(); } Don;t worry! |
| |||
| 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> |
| |||
| Re: Saving / Loading Ink Data You need to construct a new Ink object. You can't load ink into an ink object that has been populated before. Ink newInk = new Ink(); newInk.Load(...); inkPicture.Ink = newInk; Josh <njhartley******.com> wrote in message news:1174497182.309749.159490@e1g2000hsg.googlegro ups.com... > > I am trying to follow the example on: > > http://msdn2.microsoft.com/en-us/library/aa480684.aspx > > And have created a simple control - > > 1 InkPicture > 1 TextBox > 3 Buttons > > The code for the buttons are: > > private void button2_Click(object sender, EventArgs e) > { > inkPicture1.Ink.DeleteStrokes(); > inkPicture1.Refresh(); > } > > private void button1_Click(object sender, EventArgs e) > { > byte[] inkBytes = > inkPicture1.Ink.Save(PersistenceFormat.Gif); > textBox1.Text = Convert.ToBase64String(inkBytes); > } > > private void button3_Click(object sender, EventArgs e) > { > byte[] inkBytes = Convert.FromBase64String(textBox1.Text); > inkPicture1.Ink.Load(inkBytes); > inkPicture1.Invalidate(); > } > > So what I am trying to acheive is > > 1) Draw some ink on the inkpicture > 2) Click on button1 and store the ink as a Base64String somewhere > (textBox1.Text) > 3) Click on button2 to clear the page > 4) Click on button3 to restore the ink back ot the ink control > > Stage 2 seems to work - populates the textbox with a string > Stage 3 is fine - clears the picture > Stage 4 when I try to load the ink fails ("Value does not fall within > the specified range") > > What am I doing wrong? > |
| Bookmarks |
| Thread Tools | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help Saving My Data | Keith Russell | Windows Vista | 10 | 10-26-2008 03:25 AM |
| Store data on Data disk always | Low Tech Guy | Windows Vista | 1 | 07-13-2008 05:40 PM |
| Saving data on drive D: | Bobby | Windows Vista | 2 | 03-19-2008 02:50 AM |
| appdata-local-Application Data-Application Data-Application Data infinitum ad nauseum. WHY | keepout@yahoo.com.invalid | Windows Vista | 22 | 09-19-2007 12:47 AM |
| Loading Xml Data Island removes functions attached with AttachEvent | GMG | Internet Explorer | 0 | 06-21-2007 03:40 AM |
| New To Technology Questions? | Do You Need Help with Your Computer or Device? | Do You Need Help with this site? |