前一段时间接触到电子签名的集成开发,一直没写笔记,故写此随笔。为记录、也为分享,希望大家对本文的不足之处加以指正。
首先先一一介绍我所用到的方法:
确定生成文件格式
var ext = ".bmp"; if (m_ulFormat == 2) { ext = ".jpg"; } else if (m_ulFormat == 3) { ext = ".png"; } else if (m_ulFormat == 4) { ext = ".gif"; } else if (m_ulFormat == 5) { ext = ".tiff" }
将签名文件转化为Base64Encode编码(由于开发商所提供的图片保存方法有问题,以至于绕一圈保存)。
var m_ulFormat; function jsPacketsBase64Encode(ulFormat) { debugger; var obj = document.getElementById("myObject"); m_ulFormat = ulFormat; var encodeingstring = ""; //m_deviceID 设备型号判别 //ulFormat 图片格式 if (m_deviceID === 1) { encodeingstring = obj.PPNature_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 2) { encodeingstring = obj.PPL398_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 5) { encodeingstring = obj.PPL500_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 6) { encodeingstring = obj.PPE580_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 7) {; encodeingstring = obj.PPL501f_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 8) { encodeingstring = obj.PPWrite2Go_PacketsBase64Encode(m_deviceID, ulFormat); } else if (m_deviceID === 9) { encodeingstring = obj.PPL1000_PacketsBase64Encode(m_deviceID, ulFormat); } return encodeingstring; }
将base64流转化为图片
/// <summary> /// 将base64流转化为图片 /// </summary> /// <param name="imageFilePath">文件存储路径</param> /// <param name="str">Base64流</param> private void Base64StringToImage(string imageFilePath, string str) { try { byte[] bytes = Convert.FromBase64String(str); FileStream fs = new FileStream(@imageFilePath, FileMode.Create, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Close(); } catch (Exception e) { string path = "C:\\Log"; Logger log = new Logger(path); log.Log("图片生成失败!信息:" + e.Message); } }
以上即为此次电子签名开发的全部内容,为记录、也为分享。