高拍仪SDK(文豆FastSnap)

2024-04-30 17:16:06 浏览数 (1)

本sdk主要适用于bs(web)架构,可支持谷歌Chrome、火狐Firefox、360极速和安全、Edge、IE10 等支持html5的多种浏览器。

主要功能:设置裁切模式、文件格式、色彩模式、图像质量、裁边、拍照、鼠标轮滑缩放预览画面、旋转、1:1预览、适合屏幕预览、条码识别、多设备切换、分辨率选择、获取Base64 编码字符串、添加图片到PDF及合并PDF、读取身份证信息、HTTP上传文件、返回上传结果、设置色彩模式、设置去黑边、设置去底色、设置文件格式、从摄像头中识别二维码、从图片文件中识别二维码、返回二维码识别结果、添加要合并到PDF的文件、添加合并PDF的文件返回结果等,更多功能可参考开发手册。

js代码部分 首先引入js接口

代码语言:txt复制
function ConnectServer(callback, value) {

    if ('WebSocket' in window) {
        websocket = new WebSocket(url);
    } else if (window.WebSocket) {
        websocket = new WebSocket(url);
    } else if ('MozWebSocket' in window) {
        websocket = new MozWebSocket(url);
    } else {
        alert("您浏览器版本过低!请使用360、Chrome、Firefox、Edge、IE10 浏览器!");
    }

    websocket.onopen = function (e) {
        connected = true;
        heartCheck();
        isSocketConnect = true;
        clearInterval(intervalId);
        Cam_GetDevCount();
    }
    websocket.onclose = function (e) {
        connected = false;
        isSocketConnect = true;
        reconnect();
    }
    websocket.onmessage = function (e) {
        onMessage(e);
    }
    websocket.onerror = function (e) {
        isSocketConnect = true;
        reconnect();
        alert("点击确定后若无画面,请检查【文豆FastSnap】服务是否已开启!")
    };

}

function sendMessage(jsonStr) {
    connected ? websocket.send(jsonStr) : alert("未连接websocket服务器,请确保已运行服务端!")
}


/*****************************************************************************************************************/
function cameraProduceMessage(jsonObj) {

    if (jsonObj.functionName == "VideoStream") {

        img.src = "data:image/jpg;base64,"   jsonObj.imgBase64Str;
        pMainShowStartX = jsonObj.StartX;
        pMainShowStartY = jsonObj.StartY;
        img.onload = function () {

            MainContext.clearRect(0, 0, MainCanvas.width, MainCanvas.height);
            MainContext.drawImage(img, pMainShowStartX, pMainShowStartY);

            if (MainCamCutMode == 2) {
                MainContext.strokeStyle = 'blue';
                MainContext.lineWidth = 2;
                MainContext.beginPath();
                MainContext.rect(pALastX, pALastY, (pACurrentX - pALastX), (pACurrentY - pALastY));
                MainContext.closePath();
                MainContext.stroke();
            }
        }
    }

    else if (jsonObj.functionName == "VideoStream2") {
        img2.src = "data:image/jpg;base64,"   jsonObj.imgBase64Str;
        pAssistShowStartX = jsonObj.StartX;
        pAssistShowStartY = jsonObj.StartY;
        img2.onload = function () {

            AssistContext.clearRect(0, 0, AssistContext.width, AssistContext.height);
            AssistContext.drawImage(img2, pAssistShowStartX, pAssistShowStartY);
        }
    }

    else if (jsonObj.functionName == "GetDevCount") {
        var Name = new Array();
        Name = jsonObj.DevName.split('|');
        GetDevCountAndNameResultCB(jsonObj.DevCount, Name);
    }

    else if (jsonObj.functionName == "GetDevResolution") {
        var resArr = new Array();
        resArr = jsonObj.Resolution.split('|');
        GetResolutionResultCB(jsonObj.ResolutionCount, resArr);
    }

    else if (jsonObj.functionName == "Cam_Open") {
        var status = jsonObj.success;
        if (status == 0) {
            isOpenMainCamera = true;
            GetCameraOnOffStatus(0);
        }
        else {
            isOpenMainCamera = false;
            GetCameraOnOffStatus(-1);
        }
    }


    else if (jsonObj.functionName == "TakeDualCameraPhoto") {
        var filePath1 = decodeURIComponent(jsonObj.filePath1);
        var filePath2 = decodeURIComponent(jsonObj.filePath2);
        GetDualCameraPhotoResultCB(jsonObj.success, filePath1, jsonObj.Abase64, filePath2, jsonObj.Bbase64);
    }

上传文件

代码语言:txt复制
function dataURLtoFile(dataurl, filename) {

    //var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
    //bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    var bstr = atob(dataurl);
    var n = bstr.length;
    var u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }

    var suffix = filename.substring(filename.length - 3, filename.length);

    if (suffix == "jpg" || suffix == "JPG")
        return new File([u8arr], filename, { type: 'image/jpg' });
    if (suffix == "png" || suffix == "PNG")
        return new File([u8arr], filename, { type: 'image/png' });
    if (suffix == "tif" || suffix == "TIF")
        return new File([u8arr], filename, { type: 'image/tiff' });
    if (suffix == "pdf" || suffix == "PDF")
        new File([u8arr], filename, { type: 'application/pdf' });

    return new File([u8arr], filename, { type: 'application/jpg' });

0 人点赞