Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

base64 - Javascript - Dimensions of blob returned by the promise of imageCapture.takePhoto function

In the following code, I have set the max image width to 640. I am converting the blob to base64 string and then sending it to the server. On the server I am getting the image of the original width i.e. 1280. It looks like the constraints are not applied on the captured image. How do I force the returned image blob to have size of 640?

function takepicture(mediaStream) {

imageCapture = new ImageCapture(mediaStream.getVideoTracks()[0]);   
imgCapture = imageCapture.takePhoto({ imageWidth : 640}).then(function(blob) {
     reader = new FileReader();
     reader.readAsDataURL(blob); 
     reader.onloadend = function() {
        base64data = reader.result.split(',')[1];
        // base64data is uploaded to server
    }        
  }).catch(function(error) {
    console.log('error: ', error);
  });     

}

question from:https://stackoverflow.com/questions/66049005/javascript-dimensions-of-blob-returned-by-the-promise-of-imagecapture-takephot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...