What Signature Pad UWP not show image

teofilocteofiloc USMember ✭✭

Hi Guys,
Thanks in advance for your help.

I am trying to load points in signature pad for UWP.

This is my current code:

 private async void RenderImage()
        {
            //Default image source
            var fileFromSource = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///signatureLine.png"));
            var fileStream = await fileFromSource.OpenAsync(Windows.Storage.FileAccessMode.Read);

            SignatureControlImage img = this.Element as SignatureControlImage;
            BitmapImage source = new BitmapImage();

            var pointsString = "110.9615,802 110.9615,801.6539 110.9615,801.0385 111.1154,800.0385 111.5385,798.3461 113,795.0385 116.4231,788.9615 122.5,779.9615 132.0769,767.5 146.1923,752 164.9231,733.6923 187.4231,713.3846 212.6923,691.5769 240,668.1923 268.7692,642.6923 297.8077,615.5385 325.9615,587.4231 353.8077,558.6539 381.3462,529.1923 407.3077,499.8077 430.0769,472.2308 448.5769,448.0385 462.8462,428.2692 473.0385,412.8846 479.8462,400.9615 483.9231,392.1154 486,386.1538 486.6538,382.4231 486.5385,380.3462 485.8846,379.4231 484.5385,379.3846 482.4231,379.9615 479.2308,381.2692 474.6923,383.4231 468.7692,386.4615 461.8846,390.2692 454.5769,394.8462 446.8846,400.5385 438.8462,407.5769 430.2308,416.2308 421.1154,426.6538 411.7692,438.1923 402.5385,449.8846 394.2692,460.8462 387.5385,470.4231 382.6923,477.8846 379.6538,483.1154 377.8462,486.4231 376.9615,488.3462 376.6923,488.8846 376.9231,486.8077 377.7308,481.1923 379.0385,472.7692 380.6923,462.6154 382.5769,451.8462 384.8077,440.1923 387.1154,428.0385 389.6154,415.1538 392.7692,401.5385 396.9615,387.3077 402.1154,372.6923 408.8846,357.0769 417.2308,340.9231 426.9615,324.3462 437.4615,308.3462 449.0769,292.8077 462,278.4231 476.1154,265.5385 490.7692,254.7692 506.8462,246.5 524.2308,240.4231 542.5769,236.4615 560.8077,234.2308 577.9615,234.0769 594.1923,236.3846 610.5769,242.3846 627.3461,252.2692 644.5,266.3462 661.3461,284.8846 677.1539,308.6154 692.1923,339.5769 705.2692,377.9231 715.1539,422.5769 720.9231,471.8462 721.5769,523.6923 716.8846,577.2308 706.5769,630.9615 691.6154,680.8077 674.8461,722.0385 658.8461,752.8846 644.7308,773.5769 632.9615,785.8461 623.1539,791.6923 614,792.1154 604.1154,788.0385 593.0385,779.8846 580.5,768 566.1539,752.0385 550.1154,731.6154 532.7308,707.3461 514.1923,679.8846 495.2308,650 477.6923,619.4231 462.8462,589.9615 451.8846,563.6539 444.8846,541.2308 442.2308,522.6539 443.9231,506.6154 450.5769,491.5 464.1538,475.7308 487.5769,459.5385 522.4615,443.5385 568.3846,428.3077 623.4231,414.5 685.5385,403.7692 752.6923,398.1154 821.8461,396.9615 893.3461,400.4615 966.0769,408.2692 1038.115,419.5769 1107.462,435 1169.923,453.7692 1223.577,475.5769 1267.5,499.6538 1301.615,524.8077 1325.846,549.8461 1341.385,573.9615 1349.615,597.3846 1351.077,620.7692 1346.846,643.8846 1338.308,665.5 1327,684.1923 1314.038,699.3077 1300.385,710.3461 1286.538,717.5385 1272.538,720.8461 1257.115,720.5 1239.192,716.5 1218.115,708.2692 1193.423,695.1154 1164.846,676.1154 1133.423,651.6154 1099.962,622.2692 1067.577,589.8461 1038.038,552.2308 1014.923,515.2308 999.7692,481 993.8077,449.6154 998.3077,420.0769 1015.462,391.3077 1046.385,363.6154 1091.731,337.4231 1150.269,313.5385 1218.962,293 1294.423,276.9615 1373.577,264.6538 1452.654,256.0385 1528.808,250.6923 1599.038,248.7308 1661.154,250.3462 1713.462,255.6923 1755.5,265.2308 1786.962,278.4231 1808.808,295.6538 1822.5,317.7692 1829.077,344.3077 1828.769,374.1923 1822.538,405.6154 1810.846,437.5 1793.769,469.1923 1772.692,498.7692 1750.308,524.1154 1729.038,543.5769 1709.692,556.9615 1692.769,564.8077 1678.038,567.6154 1665.077,566.3461 1652.615,561.7308 1639.962,553.8461 1626,541.9615 1610.346,525.3077 1592.577,503.1154 1574.077,475.6923 1557,445.3846 1543,413.8077 1532.923,381.9231 1527.731,350.6923 1528.231,320.5 1536.962,291.0385 1555.577,261.8462 1583.308,233.8077 1620.077,207.7692 1664.462,184.4231 1714.615,164 1768.154,146.8077 1821.385,133.1538 1873.115,122.6923 1921.885,115 1965.692,110.1154 2002.923,107.9615 2032.423,108.1154 2054.231,110.1923 2069.192,114.0769 2078.846,120.0769 2084.539,128.5 2087.269,139.4231 2087.423,155 2083.846,176.5769 2076.461,203.0385 2065.039,234.3077 2049.461,268.2308 2030.346,301.6538 2009.038,332.1538 1985.577,358.6154 1961.038,379.8846 1936,395.6538 1911.577,406.1154 1887.846,412.5385 1864.654,415.6538 1841,415.5385 1816.462,411.8462 1790.308,404.9231 1762.231,395.1538 1732.154,383.3077 1701.808,369.8077 1673.231,355.9615 1647.5,342.0769 1626.231,329 1609.769,317.1538 1598,306.3077 1590.231,296.0385 1585.808,286.5 1583.962,277.3846 1584.038,268.1538 1585.115,260.4615";

            if (!string.IsNullOrEmpty(pointsString))
            {

                //Try to load points
                var pointsToLoad = ConvertToUWPPoints(pointsString);
                source = await LoadPointsAsync(pointsToLoad);
            }
            else
            {
                //Default Image
                source.SetSource(fileStream);
            }

            this.Control.Source = source;
        }

 private List<Windows.Foundation.Point> ConvertToUWPPoints(string SignaturePoints)
        {
            var baseArray = SignaturePoints.Split(new char[] { ' ' }); //this return string[] 
            var uwpPoints = new List<Windows.Foundation.Point>();

            for (int i = 0; i < baseArray.Length; i++)
            {
                var xyPoints = baseArray[i].Split(new char[] { ',' });
                if (xyPoints.Length == 2)
                    uwpPoints.Add(new Windows.Foundation.Point(double.Parse(xyPoints[0]), double.Parse(xyPoints[1])));
                else
                {
                    uwpPoints.Add(new Windows.Foundation.Point(0, 0));
                }
            }
            return uwpPoints;
        }

        private async Task<BitmapImage> LoadPointsAsync(List<Windows.Foundation.Point> points)
        {
            BitmapImage source = null;

            try
            {
                if (points != null && points.Count > 0)
                {
                    var signature = new Xamarin.Controls.SignaturePad();

                    //Loading points
                    signature.LoadPoints(points.ToArray());

                    //Image settings
                    var imageSettings = new Xamarin.Controls.ImageConstructionSettings
                    {
                        BackgroundColor = Colors.Blue, //background color
                        DesiredSizeOrScale = new Windows.Foundation.Size(300, 300),
                        StrokeColor = Colors.Black, //Line color
                        StrokeWidth = 1, //line width
                    };

                    //Getting stream
                    var stream = await signature.GetImageStreamAsync(Xamarin.Controls.SignatureImageFormat.Jpeg, imageSettings);
                    var imageStream = stream.AsRandomAccessStream();

                    //Setting source 
                    source = new BitmapImage() { DecodePixelHeight = 400, DecodePixelWidth = 400 };
                    source.SetSource(imageStream);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Insights.Report(ex);
            }

            return await Task.FromResult<BitmapImage>(source);
        }

Best Answer

  • teofilocteofiloc US ✭✭
    Accepted Answer

    I was missing the path and GeometricLine. Now is working.

Answers

Sign In or Register to comment.