无法将使用网络摄像机捕获的base64图像转换为jpeg格式以进行上传。
以下捕获/显示照片有效(请注意,我正在使用webcam.min.js(返回base64),而不是webcam.js(返回jpeg但依赖Flash)-
function take_snapshot() {
Webcam.snap( function(data_uri) {
// display results in page
document.getElementById('upload_results').innerHTML =
'<img id="imageprev" src="'+data_uri+'"/>';
} );
}
我尝试了以下方法,可能已经将Base64图像转换为Blob格式 -
function saveSnap(){
var base64image = document.getElementById("imageprev").src;
alert(base64image)
// convert base64 to raw binary data held in a string
var byteString = atob(base64image.split(',')[1]);
// separate out the mime component
var mimeString = base64image.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var dw = new DataView(ab);
for(var i = 0; i < byteString.length; i++) {
dw.setUint8(i, byteString.charCodeAt(i));
alert("arrived here");
// write the ArrayBuffer to a blob, and you're done
return new Blob([ab], {type: mimeString});
}
这个并没有实际作用,只会停止jsp的执行
let image = new Image();
image.src = base64image;
document.body.appendChild(image);
我该如何获取/查看/提取实际的JPEG文件,以便上传它(它必须是像数字.jpeg这样的东西)
JDK6 / JavaScript(请勿使用PHP)
欢迎任何想法。
祝好, Ralph