【问题标题】:I can't restore the original image from a Base30 text jSignature representation我无法从 Base30 文本 jSignature 表示中恢复原始图像
【发布时间】:2019-05-24 12:05:52
【问题描述】:

我正在尝试在我的应用程序中实现jSignature library,但我无法使其工作,实际问题是尝试从 base30 文本重新创建原始图像。为了做到这一点,我在他们的demo 中画了一些东西,取 base30 文本并将其粘贴到我的应用程序中,但生成的图像几乎与原始图像无关。我的示例应用程序的代码是这样的:

    private void BtnConvertToSVG_Click(object sender, EventArgs e)
    {
        convertFromBase30();
    }

    private void convertFromBase30()
    {
        try
        {
            jSignature.Tools.Base30Converter Base30 = new jSignature.Tools.Base30Converter();
            String base30Text = tbBase30Text.Text.ToString();
            int[][][] arrBase30 = Base30.Base30ToNative(base30Text);
            String strSVG = jSignature.Tools.SVGConverter.ToSVG(arrBase30);
            tbSVG.Text = strSVG;
            MemoryStream s = new MemoryStream(Encoding.ASCII.GetBytes(strSVG));
            SvgDocument mySVG = SvgDocument.Open<SvgDocument>(s, null);
            var tempStream = new System.IO.MemoryStream();
            mySVG.Draw().Save(tempStream, System.Drawing.Imaging.ImageFormat.Png);
            System.Drawing.Image img = System.Drawing.Image.FromStream(tempStream);
            pbImage.Image = img;
        }
        catch (Exception ex)
        {
            MessageBox.Show(String.Format("{0}", ex.Message));
        }
    }

这是一个带有两个 TextBox 的 Windows 窗体应用程序:

  • tbBase30Text:这里我介绍一下base30文本
  • tbSVG:应用编写 SVG 图像代码的位置

一个按钮 (btnConvertToSVG) 和一个 PictureBox,用于打印生成的图像。它利用了jSignature项目中包含的libraries

如果我在他们的演示中绘制 SO 图像,它会给我下一个结果

在我的应用程序中粘贴 base30 代码会得到下一个结果:

我不明白为什么,但两个签名之间唯一的共同点是行数。

这个库有一些分支,brinley 的分支(最后更新)和willowsystems 的分支是我尝试但没有成功的。

【问题讨论】:

    标签: c# jsignature


    【解决方案1】:

    感谢另一个 SO question 谈论同样的问题,我终于解决了。错误出现在要转换为 jSignature 项目中包含的 SVG 的库中。

    所有String.Format在转换String时忽略Culture在最终结果中添加错误,您可以通过在开头添加CultureInfo.InvariantCulture来修复它

    String.Format(CultureInfo.InvariantCulture, ...)
    

    【讨论】:

      猜你喜欢
      • 2018-08-26
      • 2019-05-04
      • 2021-03-25
      • 2019-05-22
      • 2013-03-21
      • 2018-01-15
      • 1970-01-01
      • 2017-08-06
      • 2013-10-02
      相关资源
      最近更新 更多