Update 20250618
This commit is contained in:
178
zz_winsign/SignControl.xaml.cs
Normal file
178
zz_winsign/SignControl.xaml.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace zz_winsign
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für SignControl.xaml
|
||||
/// </summary>
|
||||
public class imageclass
|
||||
{
|
||||
public string tgnummer { get; set; }
|
||||
public string b64 { get; set; }
|
||||
|
||||
}
|
||||
public partial class SignControl : UserControl
|
||||
{
|
||||
public string filepath { get; set; } = "";
|
||||
public string environment { get; set; }="";
|
||||
public string IgnoreI { get; set; } = "";
|
||||
public string RestURI { get; set; } = "";
|
||||
public SignControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
inkCanvas.DefaultDrawingAttributes.FitToCurve = true;
|
||||
inkCanvas.DefaultDrawingAttributes.IgnorePressure = false;
|
||||
inkCanvas.DefaultDrawingAttributes.Width = 3;
|
||||
inkCanvas.DefaultDrawingAttributes.Height = 3;
|
||||
inkCanvas.DefaultDrawingAttributes.Color = Colors.Navy;
|
||||
|
||||
inkCanvas.StylusDown += InkCanvas_StylusDown;
|
||||
inkCanvas.StylusMove += InkCanvas_StylusMove;
|
||||
|
||||
//suppress mouse and touch input (only pen)
|
||||
inkCanvas.PreviewMouseDown += (s, e) => {
|
||||
e.Handled = true;
|
||||
outputBlock.Text = "Nur Stift-Input möglich!";
|
||||
outputBlock.Foreground = Brushes.White;
|
||||
};
|
||||
inkCanvas.PreviewMouseUp += (s, e) => {
|
||||
e.Handled = true;
|
||||
outputBlock.Text = "Nur Stift-Input möglich!";
|
||||
outputBlock.Foreground = Brushes.Black;
|
||||
};
|
||||
inkCanvas.PreviewTouchDown += (s, e) => {
|
||||
e.Handled = true;
|
||||
outputBlock.Text = "Nur Stift-Input möglich!";
|
||||
outputBlock.Foreground = Brushes.White;
|
||||
};
|
||||
inkCanvas.PreviewTouchUp += (s, e) => {
|
||||
e.Handled = true;
|
||||
outputBlock.Text = "Nur Stift-Input möglich!";
|
||||
outputBlock.Foreground = Brushes.Black;
|
||||
};
|
||||
}
|
||||
|
||||
private void InkCanvas_StylusDown(object sender, StylusDownEventArgs e)
|
||||
{
|
||||
ShowStylusPoints(e.GetStylusPoints(inkCanvas));
|
||||
}
|
||||
|
||||
private void InkCanvas_StylusMove(object sender, StylusEventArgs e)
|
||||
{
|
||||
ShowStylusPoints(e.GetStylusPoints(inkCanvas));
|
||||
}
|
||||
|
||||
private void ShowStylusPoints(StylusPointCollection points)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (StylusPoint pt in points)
|
||||
{
|
||||
sb.AppendLine($"X: {pt.X:0}, Y: {pt.Y:0}, Pressure: {pt.PressureFactor:0.00}");
|
||||
}
|
||||
outputBlock.Text = sb.ToString();
|
||||
}
|
||||
private void SaveInkCanvasAsJpg(InkCanvas inkCanvas, string filename)
|
||||
{
|
||||
// 1. Größe bestimmen
|
||||
Size size = new Size(inkCanvas.ActualWidth, inkCanvas.ActualHeight);
|
||||
inkCanvas.Measure(size);
|
||||
inkCanvas.Arrange(new Rect(size));
|
||||
|
||||
// 2. RenderTargetBitmap erstellen
|
||||
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
|
||||
(int)size.Width,
|
||||
(int)size.Height,
|
||||
96d, // DPI-Wert
|
||||
96d, // DPI-Wert
|
||||
PixelFormats.Default);
|
||||
renderBitmap.Render(inkCanvas);
|
||||
|
||||
// 3. Encoder erstellen und Frame hinzufügen
|
||||
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
|
||||
encoder.QualityLevel = 95;
|
||||
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
|
||||
|
||||
// 4. In Datei speichern
|
||||
using (FileStream file = File.Create(filename))
|
||||
{
|
||||
encoder.Save(file);
|
||||
}
|
||||
}
|
||||
|
||||
private string get_tg(string tguser)
|
||||
{
|
||||
if (IgnoreI.ToString().ToLower() == "true")
|
||||
{
|
||||
|
||||
tguser = tguser.Replace("I", "");
|
||||
tguser = tguser.Replace("i", "");
|
||||
}
|
||||
return tguser;
|
||||
}
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
string SaveImageFolder = filepath;
|
||||
string SaveImageFilename = SaveImageFolder + "signatureimage.jpg";
|
||||
SaveInkCanvasAsJpg(inkCanvas, SaveImageFilename);
|
||||
|
||||
byte[] imageArray = System.IO.File.ReadAllBytes(SaveImageFilename);
|
||||
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
|
||||
|
||||
string URL = RestURI;
|
||||
URL = URL + "API/SaveSignature";
|
||||
string tguser = get_tg(Environment.UserName);
|
||||
string json = "{\"tgnummer\":\"" + tguser + "\", \"b64\":\"" + base64ImageRepresentation + "\"}";
|
||||
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
var token = "";
|
||||
if (environment == "INT") { token = "ecJVgQbmauycFRw5Lz6hB0dJb6GYCePckr2kw3g+xLkbS+h6oxR0iPMFkP3uXpFq7luWAdXrEWs1kmR4Pan5rN+bgwm2YjdPl56Et/Z5hIr+QJhPMB8lmNO1oJytu3GS"; }
|
||||
if (environment == "PROD") { token = "U/atwlLxw8w3RRK3iRhIidhhz/MR+dgQaysvuWjLyjjy9G3edGldU1zUEATZMZ5v1wPvA5ArDqAGH4xsqoyEP+w6k5Ij0Rh47ifP/8iN0jE418ECp9TbOX8Vrg6JyGFkfLjIAk+uQQC18dg4wGnOwKEJJlKrGCYeVVwwsOBtsoM="; }
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = client.PostAsync(URL, content);
|
||||
outputBlock.Text = response.Result.StatusCode.ToString();
|
||||
}
|
||||
|
||||
System.IO.File.Delete(SaveImageFilename);
|
||||
}
|
||||
|
||||
private void DelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
inkCanvas.Strokes.Clear();
|
||||
}
|
||||
|
||||
private void OnOffSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||||
{
|
||||
if (OnOffSlider.Value == 0)
|
||||
{
|
||||
inkCanvas.DefaultDrawingAttributes.Width = 2;
|
||||
inkCanvas.DefaultDrawingAttributes.Height = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
inkCanvas.DefaultDrawingAttributes.Width = 3;
|
||||
inkCanvas.DefaultDrawingAttributes.Height = 3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user