将Topaz签名字符串(十六进制)转换为图像 [英] Convert Topaz Signature String (Hexadecimal) to Image

查看:272
本文介绍了将Topaz签名字符串(十六进制)转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将topaz签名板集成到我的ColdFusion应用程序中。我想从pad中捕获签名,将其转换为ColdFusion可以在浏览器中显示并保存到磁盘的格式。



使用他们的文档,我可以以十六进制格式(I think)检索捕获的签名。我按照在其网站上找到的文档:基本Javascript演示



然后我尝试将十六进制转换为Base64,以便我可以将图像写入浏览器和ColdFusion服务器的磁盘。但是ColdFusion似乎不喜欢我的格式,并且抛出一个错误。



任何人都可以帮我这个?



以下是转换十六进制字符串并尝试从中创建图像的代码。

 < cfoutput> ; 

表单资料:#form.sigImageData#< br />

< cfscript>
binaryValue = binaryDecode(form.sigImageData,hex);
base64Value = binaryEncode(binaryValue,base64);
< / cfscript>

已转换数据:#base64Value#< br />

< center>
< cfimage
action =write
destination =c:\V:\Inetpub\wwwroot\signatures\test.png
source = #base64Value#
/>
< / center>

< / cfoutput>

JavaScript由制造商提供:

 < script type =text / javascript> 
var Index;

function pluginLoaded()
{
// alert(Plugin loaded!
}

function onClear()
{
document.getElementById('sigplus')。clearSignature();
}

function onSign()
{
document.getElementById('sigplus')。tabletState = 1;
document.getElementById('sigplus')。captureMode = 1;
Index = setInterval(Refresh,50);

document.getElementById('sigplus')。antiAliasSpotSize = .85;
document.getElementById('sigplus')。antiAliasLineScale = .55;
}


function onDone()
{
if(document.getElementById('sigplus')。totalPoints == 0)
{
alert(请在继续前签名);
return false;
}
else
{
document.getElementById('sigplus')。tabletState = 0;
clearInterval(Index);

// RETURN TOPAZ-FORMAT SIGSTRING
document.getElementById('sigplus')。compressionMode = 1;
document.SigForm.bioSigData.value = document.getElementById('sigplus')。sigString;
document.SigForm.sigStringData.value + = document.getElementById('sigplus')。sigString;

//这将返回Topaz自身格式的签名,带有生物特征信息


//返回BMP字节数组转换为HEXADECIMAL STRING
文档。 getElementById('sigplus')。imageXSize = 500;
document.getElementById('sigplus')。imageYSize = 100;
document.getElementById('sigplus')。penWidth = 5;
//SigPlus1.JustifyMode = 5;
var bmpString ='';
document.getElementById('sigplus')。bitmapBufferWrite(5);
var bmpSize = document.getElementById('sigplus')。bitmapBufferSize();
for(var a = 0; a< bmpSize; a ++)
{
var byte = document.getElementById('sigplus')。bitmapBufferByte(a).toString(16)
if(byte.length === 1)
{
bmpString + ='0';
}
bmpString + = byte;
}
document.SigForm.sigImageData.value + = bmpString;
document.SigForm.sigImgData.value = bmpString;
//此示例返回转换为十六进制字符串的位图图像
//将字符串转换回服务器上的字节数组以进行最终成像


文档.SigForm.submit(); // SUBMIT FOR FORM HERE
}

}

function Refresh()
{
document.getElementById('sigplus')。 refreshEvent();
}


< / script>

这是My ColdFusion错误输出: b

您正在访问的网站遇到意外错误。请联系网站管理员。



以下信息供网站开发者用于调试目的。处理请求时发生错误尝试读取图像时发生异常。



错误发生在C:\Inetpub\wwwroot\serviceticket\sigpad \action.cfm:line 29
27:action =writeToBrowser
28:source =#binaryValue#
29:isBase64 =no>
30:
31:资源:检查ColdFusion文档以验证您是否使用正确的语法。搜索知识库以找到问题的解决方案。浏览器Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 32.0.1700.102 Safari / 537.36远程地址192.168.10.103引荐来源 https://jaydien.ezservicetrax.com/serviceticket/sigpad/index.cfm 日期/时间11-Mar-14 03:37 PM堆栈跟踪在cfaction2ecfm1686568327 .runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29)



coldfusion.image.ImageReader $ ImageReadingException:在尝试读取图像时发生。在coldfusion.image.ImageReader.readImage(ImageReader.java:133)在coldfusion.image.Image。(Image.java:132)在coldfusion.tagext.io.ImageTag.doStartTag(ImageTag.java:401)在coldfusion.runtime .cfJspPage._emptyTcfTag(CfJspPage.java:2661)at cfaction2ecfm1686568327.runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29)在coldfusion.runtime.CfJspPage.invoke(CfJspPage.java :196)at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:483)在coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)在coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:288)在coldfusion.filter.MonitorFilter.invoke(MonitoringFilter.java:40)在coldfusion.filter.PathFilter.invoke(PathFilter.java:86)在coldfusion.filter的ColdFusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)。在ColdFusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter())在ColdFusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) .java:46)在coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)在coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)在coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)在coldfusion.monitor.event上的coldfusion.CfmServlet.service(CfmServlet.java:198)at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)。监控ServletFilter.doFilter(MonitoringServletFilter.java:42)在coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)在jrun.servlet.FilterChain.doFilter(FilterChain.java:94)在jrun.servlet.FilterChain.service(FilterChain .java:101)在jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)在jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)在jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)at jrunx.scheduler.ThreadPool $ DownstreamMetrics.invokeRunnable(ThreadPool.java:320)at jrunx.scheduler.ThreadPool $ ThreadThrottle.invokeRunnable(ThreadPool.java:428)at jrunx.scheduler.ThreadPool $ UpstreamMetrics.invokeRunnable(ThreadPool.java:266)at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

解决方案

(更多评论,但有点太长了...)



我使用CF9测试了示例十六进制字符串,得到的结果相同。虽然文件头,事实,你可以打开它与MS油漆,建议它是一个位图,我不知道什么类型/格式Topaz返回。 (截图API目前为止还没有任何相关的东西)



作为一个临时的解决方法,你可以使用.net对象。使用 <$ c加载文件$ c> System.Drawing.Bitmap 并将其重写到磁盘。结果应该是与 cfimage 兼容的位图。这个解决方案不理想,由于双写。但是,这是一个临时选项,而您进一步调查返回的格式。

 < cfscript> 
//解码十六进制并将二进制文件保存到文件
binaryData = binaryDecode(orm.sigImageData,hex);
saveToPath =c:/temp/original.bmp;
fileWrite(saveToPath,binaryData);
//使用.net
加载和重命名Bitmap = createObject(。net,System.Drawing.Bitmap)。init(saveToPath);
Bitmap.Save(c:/temp/new.bmp);
// .. cleanup
< / cfscript>

<!--- display new image --->
< cfimage action =writeToBrowsersource =c:/temp/new.bmp/>


I am trying to integrate a topaz signature pad into my ColdFusion application. I would like to capture the signature from the pad, convert it to format that ColdFusion can show in the browser and save to the disk.

Using their documentation, I am able to retrieve the captured signature in a Hexadecimal format (I think). I am following the documentation found on their site here: Basic Javascript Demo

I have then tries to convert that Hexadecimal to Base64 so that I can write the image to the browser and the disk of the ColdFusion server. However ColdFusion doesn't seem to like my format and throw an error.

Can anybody help me with this??

Here is the code that converts the Hexadecimal string and also tries to make an image out of it.

<cfoutput>

Form Data: #form.sigImageData#<br />

<cfscript>
binaryValue = binaryDecode( form.sigImageData, "hex" );
    base64Value = binaryEncode( binaryValue, "base64" );
</cfscript>

Converted Data: #base64Value#<br />

<center>
<cfimage
action="write"
destination="c:\V:\Inetpub\wwwroot\signatures\test.png"
source="#base64Value#"
/>
</center>

</cfoutput>

Javascript Provided By Manufacturer:

<script type="text/javascript">
var Index;

function pluginLoaded()
    {
    //alert("Plugin loaded!");
    }

function onClear()
    {
    document.getElementById('sigplus').clearSignature();
    }

function onSign()
    {
    document.getElementById('sigplus').tabletState = 1;
    document.getElementById('sigplus').captureMode = 1;
    Index = setInterval(Refresh, 50);

            document.getElementById('sigplus').antiAliasSpotSize = .85;
            document.getElementById('sigplus').antiAliasLineScale = .55;
    }


function onDone()
    {
            if(document.getElementById('sigplus').totalPoints==0)
               {
               alert("Please sign before continuing");
               return false;
               }
            else
               {
       document.getElementById('sigplus').tabletState = 0;
               clearInterval(Index);

               //RETURN TOPAZ-FORMAT SIGSTRING
               document.getElementById('sigplus').compressionMode=1;
               document.SigForm.bioSigData.value=document.getElementById('sigplus').sigString;
               document.SigForm.sigStringData.value+=document.getElementById('sigplus').sigString;

               //this returns the signature in Topaz's own format, with biometric information


               //RETURN BMP BYTE ARRAY CONVERTED TO HEXADECIMAL STRING
               document.getElementById('sigplus').imageXSize = 500;
               document.getElementById('sigplus').imageYSize = 100;
               document.getElementById('sigplus').penWidth = 5;
               //SigPlus1.JustifyMode = 5;
               var bmpString = '';
               document.getElementById('sigplus').bitmapBufferWrite(5);
               var bmpSize = document.getElementById('sigplus').bitmapBufferSize();
               for(var a = 0; a < bmpSize; a++)
               {
                 var byte =    document.getElementById('sigplus').bitmapBufferByte(a).toString(16);
                 if(byte.length === 1)
                 {
                    bmpString += '0';
                 }
                 bmpString += byte;
               }
               document.SigForm.sigImageData.value+=bmpString;
               document.SigForm.sigImgData.value=bmpString;
               //this example returns a bitmap image converted to a hexadecimal string
               //convert the string back to a byte array on the server for final imaging


               document.SigForm.submit(); //SUBMIT THE FORM HERE
               }

    }

function Refresh()
    {
    document.getElementById('sigplus').refreshEvent();
    }


</script>

Here is My ColdFusion Error Output:

The web site you are accessing has experienced an unexpected error. Please contact the website administrator.

The following information is meant for the website developer for debugging purposes. Error Occurred While Processing Request An exception occurred while trying to read the image.

'' The error occurred in C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm: line 29 27 : action="writeToBrowser" 28 : source="#binaryValue#" 29 : isBase64="no"> 30 : 31 : Resources: Check the ColdFusion documentation to verify that you are using the correct syntax. Search the Knowledge Base to find a solution to your problem. Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36 Remote Address 192.168.10.103 Referrer https://jaydien.ezservicetrax.com/serviceticket/sigpad/index.cfm Date/Time 11-Mar-14 03:37 PM Stack Trace at cfaction2ecfm1686568327.runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29)

coldfusion.image.ImageReader$ImageReadingException: An exception occurred while trying to read the image. at coldfusion.image.ImageReader.readImage(ImageReader.java:133) at coldfusion.image.Image.(Image.java:132) at coldfusion.tagext.io.ImageTag.doStartTag(ImageTag.java:401) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2661) at cfaction2ecfm1686568327.runPage(C:\Inetpub\wwwroot\serviceticket\sigpad\action.cfm:29) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:483) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:288) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:86) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:198) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

解决方案

(More of a comment, but a bit too long ...)

I tested the sample hex string with CF9 and got the same result. While the file header, and fact that you can open it with MS Paint, suggests it is a bitmap, I am not sure exactly what type/format Topaz is returning. (Skimming the API did not turn up anything pertinent so far)

As a temporary work-around, you could use .net objects. Load the file with System.Drawing.Bitmap and rewrite it to disk. The result should be a bitmap compatible with cfimage. This solution is not ideal, due to the double write. However, it is an interim option, while you investigate the returned format further.

<cfscript>
    // decode hex and save binary to file
    binaryData = binaryDecode(orm.sigImageData, "hex");
    saveToPath = "c:/temp/original.bmp";
    fileWrite(saveToPath, binaryData);
    // load and resave with .net
    Bitmap = createObject(".net", "System.Drawing.Bitmap").init(saveToPath);
    Bitmap.Save("c:/temp/new.bmp");
    // .. cleanup     
</cfscript>

<!--- display new image --->
<cfimage action="writeToBrowser" source="c:/temp/new.bmp" />

这篇关于将Topaz签名字符串(十六进制)转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆