Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery网络摄像头插件使用java将图像上传到服务器_Java_Jquery_Html_Jsp_Spring Mvc - Fatal编程技术网

Jquery网络摄像头插件使用java将图像上传到服务器

Jquery网络摄像头插件使用java将图像上传到服务器,java,jquery,html,jsp,spring-mvc,Java,Jquery,Html,Jsp,Spring Mvc,我想知道是否有一种方法可以使用java将图像上传到服务器。我使用的是jquery网络摄像头插件,他们有一个脚本可以做到这一点,但是我没有使用php,我使用的是SpringMVC(java) 我不确定是否有办法将SpringMVC项目配置为同时使用php和java。这就是我到目前为止所做的: 代码 var pos = 0, ctx = null, saveCB, image = []; var canvas = document.createElement('canvas'); c

我想知道是否有一种方法可以使用java将图像上传到服务器。我使用的是jquery网络摄像头插件,他们有一个脚本可以做到这一点,但是我没有使用php,我使用的是SpringMVC(java)

我不确定是否有办法将SpringMVC项目配置为同时使用php和java。这就是我到目前为止所做的:

代码

var pos = 0, ctx = null, saveCB, image = [];
    var canvas = document.createElement('canvas');
    canvas.setAttribute('width', 320);
    canvas.setAttribute('height', 240);
    ctx = canvas.getContext('2d');
    image = ctx.getImageData(0, 0, 320, 240);

var saveCB = function (data) {
    var col = data.split(';');
    var img = image;
    for (var i = 0; i < 320; i++) {
        var tmp = parseInt(col[i]);
        img.data[pos + 0] = (tmp >> 16) & 0xff;
        img.data[pos + 1] = (tmp >> 8) & 0xff;
        img.data[pos + 2] = tmp & 0xff;
        img.data[pos + 3] = 0xff;
        pos += 4;
    }

    if (pos >= 4 * 320 * 240) {
        ctx.putImageData(img, 0, 0);
        foto = canvas.toDataURL("image/png");
        $("#photo").val(foto);
        pos = 0;
    }
};

将图像绘制到画布后 使用
canvas.toDataURL()
-返回图像的base64编码数据作为请求参数

然后在后端,使用
Base64.decodeBase64(字符串数据)
将编码数据解码为字节数组:

//@RequestParam data

//remove mimeType declaration in the data string first

String byteStr = data.split(",")[1];


//get the byte array of the data

byte[] bytes = Base64.decodeBase64(byteStr);
//@RequestParam data

//remove mimeType declaration in the data string first

String byteStr = data.split(",")[1];


//get the byte array of the data

byte[] bytes = Base64.decodeBase64(byteStr);