我无法从 Base30 文本 jSignature 表示中恢复原始图像
I can't restore the original image from a Base30 text jSignature representation
我正在尝试实现 jSignature library in my application but I can't make it work, the actual problem is trying to recreate the original image from the base30 text. In order to do it I draw something in their 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));
}
}
这是一个 Windows 具有两个文本框的表单应用程序:
- tbBase30Text:这里我介绍base30文本
- tbSVG:应用写入SVG图像代码的地方
一个按钮 (btnConvertToSVG) 和一个 PictureBox,我在其中打印生成的图像。它利用了 libraries included in the jSignature 项目
如果我在他们的演示中绘制 SO 图像,它会给出下一个结果
在我的应用程序中粘贴 base30 代码会得到下一个结果:
我不明白为什么,但两个签名之间唯一的共同点是行数。
这个库有一些分支,brinley's one (last updated) and the willowsystems 是我试过但没有成功。
我终于解决了,感谢另一个SO question谈论同样的问题。错误是在库中转换为 jSignature 项目中包含的 SVG。
所有String.Format
在转换String
时忽略Culture
添加错误到最终结果,你可以通过添加CultureInfo.InvariantCulture
来修复它开头
String.Format(CultureInfo.InvariantCulture, ...)
我正在尝试实现 jSignature library in my application but I can't make it work, the actual problem is trying to recreate the original image from the base30 text. In order to do it I draw something in their 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));
}
}
这是一个 Windows 具有两个文本框的表单应用程序:
- tbBase30Text:这里我介绍base30文本
- tbSVG:应用写入SVG图像代码的地方
一个按钮 (btnConvertToSVG) 和一个 PictureBox,我在其中打印生成的图像。它利用了 libraries included in the jSignature 项目
如果我在他们的演示中绘制 SO 图像,它会给出下一个结果
在我的应用程序中粘贴 base30 代码会得到下一个结果:
我不明白为什么,但两个签名之间唯一的共同点是行数。
这个库有一些分支,brinley's one (last updated) and the willowsystems 是我试过但没有成功。
我终于解决了,感谢另一个SO question谈论同样的问题。错误是在库中转换为 jSignature 项目中包含的 SVG。
所有String.Format
在转换String
时忽略Culture
添加错误到最终结果,你可以通过添加CultureInfo.InvariantCulture
来修复它开头
String.Format(CultureInfo.InvariantCulture, ...)