Answered by:
Show signature from byte array on canvas

Question
-
Hello everyone,
I am trying to draw a signature on canvas from byte array. Here is my code. When i am run this code, this error is come:
Error HRESULT E_FAIL has been returned from a call to a COM component.
Here is my code:
//strbase64 is base64 string Byte[] ByteOutput = System.Text.Encoding.UTF8.GetBytes(strbase64); using (var stream2 = new InMemoryRandomAccessStream()) { await stream2.WriteAsync(ByteOutput.AsBuffer()); await stream2.FlushAsync(); stream2.Seek(0); await _inkManager.LoadAsync(stream2); if (_inkManager.GetStrokes().Count > 0) { RenderStrokes(); }
Thursday, January 2, 2014 5:42 AM
Answers
-
I successful solved my problem. There is an error during convert outputstream to byte array.
- Marked as answer by Khant Nipun Friday, January 3, 2014 4:37 AM
Friday, January 3, 2014 4:37 AM
All replies
-
Where do you get the exception?
What is strbase64? Where does it come from and are you sure it is a valid ISF file?
--Rob
Thursday, January 2, 2014 6:40 AMModerator -
Hello Rob,
strbase64 is base64 string, and exception comes at This line:
await _inkManager.LoadAsync(stream2);
Thursday, January 2, 2014 7:41 AM -
Try this.
Byte[] ByteOutput = System.Text.Encoding.UTF8.GetBytes(strbase64); MemoryStream stream = new MemoryStream(ByteOutput); var randomAccessStream = new MemoryRandomAccessStream(stream); await _inkManager.LoadAsync(randomAccessStream);
MemoryRandomAccessStream class is available here.
public class MemoryRandomAccessStream : IRandomAccessStream { private Stream m_InternalStream; public MemoryRandomAccessStream(Stream stream) { this.m_InternalStream = stream; } public MemoryRandomAccessStream(byte[] bytes) { this.m_InternalStream = new MemoryStream(bytes); } public IInputStream GetInputStreamAt(ulong position) { this.m_InternalStream.Seek((long)position, SeekOrigin.Begin); return this.m_InternalStream.AsInputStream(); } public IOutputStream GetOutputStreamAt(ulong position) { this.m_InternalStream.Seek((long)position, SeekOrigin.Begin); return this.m_InternalStream.AsOutputStream(); } public ulong Size { get { return (ulong)this.m_InternalStream.Length; } set { this.m_InternalStream.SetLength((long)value); } } public bool CanRead { get { return true; } } public bool CanWrite { get { return true; } } public IRandomAccessStream CloneStream() { throw new NotSupportedException(); } public ulong Position { get { return (ulong)this.m_InternalStream.Position; } } public void Seek(ulong position) { this.m_InternalStream.Seek((long)position, 0); } public void Dispose() { this.m_InternalStream.Dispose(); } public Windows.Foundation.IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options) { var inputStream = this.GetInputStreamAt(0); return inputStream.ReadAsync(buffer, count, options); } public Windows.Foundation.IAsyncOperation<bool> FlushAsync() { var outputStream = this.GetOutputStreamAt(0); return outputStream.FlushAsync(); } public Windows.Foundation.IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer) { var outputStream = this.GetOutputStreamAt(0); return outputStream.WriteAsync(buffer); } }
Thursday, January 2, 2014 11:43 AM -
I have another problem,
how to convert ioutputstream to bytearray, my code:
Windows.Storage.Pickers.FileSavePicker save = new Windows.Storage.Pickers.FileSavePicker(); save.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; save.DefaultFileExtension = ".png"; save.FileTypeChoices.Add("PNG", new string[] { ".png" }); StorageFile filesave = await save.PickSaveFileAsync(); IOutputStream ab = await filesave.OpenAsync(FileAccessMode.ReadWrite);
Thursday, January 2, 2014 12:49 PM -
I successful solved my problem. There is an error during convert outputstream to byte array.
- Marked as answer by Khant Nipun Friday, January 3, 2014 4:37 AM
Friday, January 3, 2014 4:37 AM