private void Initialize() { var grid = new Grid(); inkPresenter = new InkPresenter(); inkPresenter.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); inkPresenter.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch); inkPresenter.Background = new SolidColorBrush(Colors.Transparent); grid.Children.Add(inkPresenter); inkPresenter.MouseLeftButtonDown += OnMouseDown; inkPresenter.MouseMove += OnMouseMove; inkPresenter.MouseLeftButtonUp += OnMouseUp; inkPresenter.LostMouseCapture += OnMouseLost; // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; HorizontalContentAlignment = HorizontalAlignment.Stretch; VerticalContentAlignment = VerticalAlignment.Stretch; Content = grid; }
private void Initialize() { var grid = new Grid(); inkPresenter = new InkPresenter(); inkPresenter.ClipToBounds = true; inkPresenter.StrokeCompleted += OnStrokeCompleted; inkPresenter.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); inkPresenter.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch); grid.Children.Add(inkPresenter); // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; HorizontalContentAlignment = HorizontalAlignment.Stretch; VerticalContentAlignment = VerticalAlignment.Stretch; Content = grid; IsEnabledChanged += delegate { inkPresenter.IsInputEnabled = IsEnabled; }; }
private void Initialize() { var grid = new Grid(); inkCanvas = new InkCanvas(); inkCanvas.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); inkCanvas.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch); grid.Children.Add(inkCanvas); inkPresenter = inkCanvas.InkPresenter; inkPresenter.StrokesCollected += (sender, e) => OnStrokeCompleted(); inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Touch | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse; // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; HorizontalContentAlignment = HorizontalAlignment.Stretch; VerticalContentAlignment = VerticalAlignment.Stretch; Content = grid; IsEnabledChanged += delegate { inkPresenter.IsInputEnabled = IsEnabled; }; }
private bool GetImageConstructionArguments(ImageConstructionSettings settings, out NativeSize scale, out NativeRect signatureBounds, out NativeSize imageSize, out float strokeWidth, out NativeColor strokeColor, out NativeColor backgroundColor) { settings.ApplyDefaults((float)StrokeWidth, StrokeColor); if (IsBlank || settings.DesiredSizeOrScale?.IsValid != true) { scale = default(NativeSize); signatureBounds = default(NativeRect); imageSize = default(NativeSize); strokeWidth = default(float); strokeColor = default(NativeColor); backgroundColor = default(NativeColor); return(false); } var sizeOrScale = settings.DesiredSizeOrScale.Value; var viewSize = this.GetSize(); imageSize = sizeOrScale.GetSize((float)viewSize.Width, (float)viewSize.Height); scale = sizeOrScale.GetScale((float)imageSize.Width, (float)imageSize.Height); if (settings.ShouldCrop == true) { signatureBounds = GetSignatureBounds(settings.Padding.Value); if (sizeOrScale.Type == SizeOrScaleType.Size) { // if a specific size was set, scale to that var scaleX = imageSize.Width / (float)signatureBounds.Width; var scaleY = imageSize.Height / (float)signatureBounds.Height; if (sizeOrScale.KeepAspectRatio) { scaleX = scaleY = Math.Min((float)scaleX, (float)scaleY); } scale = new NativeSize((float)scaleX, (float)scaleY); } else if (sizeOrScale.Type == SizeOrScaleType.Scale) { imageSize.Width = signatureBounds.Width * scale.Width; imageSize.Height = signatureBounds.Height * scale.Height; } } else { signatureBounds = new NativeRect(0, 0, viewSize.Width, viewSize.Height); } strokeWidth = settings.StrokeWidth.Value; strokeColor = (NativeColor)settings.StrokeColor; backgroundColor = (NativeColor)settings.BackgroundColor; return(true); }
/// <summary> /// Create an encoded image stream of the currently drawn signature using the specified settings. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, ImageConstructionSettings settings) { NativeSize scale; NativeRect signatureBounds; NativeSize imageSize; float strokeWidth; NativeColor strokeColor; NativeColor backgroundColor; if (GetImageConstructionArguments(settings, out scale, out signatureBounds, out imageSize, out strokeWidth, out strokeColor, out backgroundColor)) { return(GetImageStreamInternal(format, scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor)); } return(Task.FromResult <Stream> (null)); }
/// <summary> /// Create an image of the currently drawn signature using the specified settings. /// </summary> public NativeImage GetImage(ImageConstructionSettings settings) { NativeSize scale; NativeRect signatureBounds; NativeSize imageSize; float strokeWidth; NativeColor strokeColor; NativeColor backgroundColor; if (GetImageConstructionArguments(settings, out scale, out signatureBounds, out imageSize, out strokeWidth, out strokeColor, out backgroundColor)) { return(GetImageInternal(scale, signatureBounds, imageSize, strokeWidth, strokeColor, backgroundColor)); } return(null); }
private void Initialize() { inkPresenter = new InkPresenter(); inkPresenter.ClipToBounds = true; inkPresenter.StrokeCompleted += OnStrokeCompleted; inkPresenter.SetValue(Grid.HorizontalAlignmentProperty, Windows.UI.Xaml.HorizontalAlignment.Stretch); inkPresenter.SetValue(Grid.VerticalAlignmentProperty, Windows.UI.Xaml.VerticalAlignment.Stretch); Children.Add(inkPresenter); // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; }
private void Initialize() { inkPresenter = new InkPresenter(Context) { LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent) }; inkPresenter.StrokeCompleted += OnStrokeCompleted; AddView(inkPresenter); // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; }
private void Initialize(bool baseProperties = true) { inkPresenter = new InkPresenter(Bounds) { AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight, }; inkPresenter.StrokeCompleted += OnStrokeCompleted; AddSubview(inkPresenter); // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor; }
/// <summary> /// Create an encoded image of the currently drawn signature using the specified settings. /// </summary> public Task <Stream> GetImageStreamAsync(SignatureImageFormat format, ImageConstructionSettings settings) { return(SignaturePadCanvas.GetImageStreamAsync(format, settings)); }
/// <summary> /// Create an image of the currently drawn signature using the specified settings. /// </summary> public WriteableBitmap GetImage(ImageConstructionSettings settings) { return(SignaturePadCanvas.GetImage(settings)); }
/// <summary> /// Create an image of the currently drawn signature using the specified settings. /// </summary> public UIImage GetImage(ImageConstructionSettings settings) { return(SignaturePadCanvas.GetImage(settings)); }