Create bitmap from Inkcanvas Strokes
I'm trying to create a bitmap out of the strokes in an inkcanvas but i keep getting an error. I'm not sure why. Ill post the code and what line i keep getting the error at. The error is System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Stream stream)
at MeasureTest.Window1.Analyze() in ...\Window1.xaml.vb:line 109
I appreciate any help anyone can give me.
Code:
Dim ms As New MemoryStream
ink1.Strokes.Save(ms)
Dim bits As Byte() = ms.ToArray
Dim memorybits As New MemoryStream(bits)
Dim bitmap As New System.Drawing.Bitmap(memorybits) 'Error Here **********
Dim bit As BitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap, IntPtr.Zero, Int32Rect.Empty, _
BitmapSizeOptions.FromEmptyOptions())
Dim Testimage As New Image
Testimage.Source = CType(bit, ImageSource)
Re: Create bitmap from Inkcanvas Strokes
import Microsoft.Ink.Dll
Code:
Dim sc As StrokeCollection = ink1.Strokes
Dim inkData As Byte() = Nothing
Using inkMemStream As New MemoryStream
sc.Save(inkMemStream)
inkData = inkMemStream.ToArray()
End Using
Dim gifData As Byte() = Nothing
Using ink2 As New Microsoft.Ink.Ink()
ink2.Load(inkData)
gifData = ink2.Save(Microsoft.Ink.PersistenceFormat.Gif)
End Using
File.WriteAllBytes("c://strokes.gif", gifData)