Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<Window x:Class="MainWindow"
Title="Pocowrite" Height="176" Width="435">
<Grid Background="#40444b">
<InkCanvas Margin="12,12,12,38" Name="InkCanvas1" Background="#36393f" MinHeight="1" MinWidth="1" />
<Button Content="Copy" HorizontalAlignment="Left" Margin="12,0,0,12" Name="CopyBtn" Width="75" Height="23" VerticalAlignment="Bottom" />
<Button Content="Clear" HorizontalAlignment="Right" Margin="0,0,12,12" Name="ClearBtn" Width="75" Background="#FFDDDDDD" Height="23" VerticalAlignment="Bottom" />
Imports System.IO
Imports System.Drawing
Class MainWindow
Private Function SignatureToBitmapBytes() As Byte()
'Dim margin As Integer = CInt(InkCanvas1.Margin.Left)
'Dim width As Integer = CInt(InkCanvas1.ActualWidth) - margin
'Dim height As Integer = CInt(InkCanvas1.ActualHeight) - margin
'Dim rtb As RenderTargetBitmap = New RenderTargetBitmap(width, height, 96.0R, 96.0R, PixelFormats.[Default])
Dim rtb As New RenderTargetBitmap(InkCanvas1.ActualWidth, InkCanvas1.ActualHeight, 96.0R, 96.0R, PixelFormats.[Default])
'Dim bvm As New BitmapVisualManager(rtb)
Dim dvInk As New DrawingVisual
Dim dcInk As DrawingContext = dvInk.RenderOpen()
Dim bgpen As New Windows.Media.Pen
bgpen.Brush = New Windows.Media.SolidColorBrush(Windows.Media.Color.FromRgb(54, 57, 63))
dcInk.DrawRectangle(New Windows.Media.SolidColorBrush(Windows.Media.Color.FromRgb(54, 57, 63)), bgpen, New Rect(0D, 0D,
InkCanvas1.ActualWidth, InkCanvas1.ActualHeight))
For Each stroke In InkCanvas1.Strokes
Dim encoder As BmpBitmapEncoder = New BmpBitmapEncoder()
Dim bitmapBytes As Byte()
Using ms As MemoryStream = New MemoryStream()
ms.Position = 0
bitmapBytes = ms.ToArray()
End Using
Return bitmapBytes
End Function
Private Sub CopyBtn_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CopyBtn.Click
My.Computer.Clipboard.SetImage(New Bitmap(New MemoryStream(SignatureToBitmapBytes)))
End Sub
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
InkCanvas1.DefaultDrawingAttributes.Color = Colors.White
End Sub
Private Sub ClearBtn_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles ClearBtn.Click
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment