Created
January 3, 2021 04:50
-
-
Save dotcomboom/fa5aafcb9febdb3aa815c7e7a2fb4c6f to your computer and use it in GitHub Desktop.
Pocowrite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
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" /> | |
</Grid> | |
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.IO | |
Imports System.Drawing | |
Class MainWindow | |
Private Function SignatureToBitmapBytes() As Byte() | |
'https://www.centrolutions.com/blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx | |
'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]) | |
'rtb.Render(InkCanvas1) | |
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 | |
stroke.Draw(dcInk) | |
Next | |
dcInk.Close() | |
rtb.Render(dvInk) | |
' https://microsoft.public.windows.developer.winfx.avalon.narkive.com/vwqGNgNA/how-get-image-from-inkcanvas | |
Dim encoder As BmpBitmapEncoder = New BmpBitmapEncoder() | |
encoder.Frames.Add(BitmapFrame.Create(rtb)) | |
Dim bitmapBytes As Byte() | |
Using ms As MemoryStream = New MemoryStream() | |
encoder.Save(ms) | |
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 | |
InkCanvas1.Strokes.Clear() | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment