我使用https://graph.microsoft.com/beta/me/photo/ $ value API来获取outlook用户的个人资料图片.我得到了一个关于在rest-client中运行上述API的图像.API的内容类型是"image/jpg"
但是,在Node.js中,API的响应如下:
????\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000??\u0000?\u0000\u0005\u0005\u0005\u0005\u0005\u0005\u0006\u0006\u0006\u0006\b\t\b\t\b\f\u000b\n\n\u000b\f\u0012\r\u000e\r\u000e\r\u0012\u001b\u0011\u0014\u0011\u0011\u0014\u0011\u001b\u0018\u001d\u0018\u0016\u0018\u001d\u0018+"\u001e\u001e"+2*(*2<66<LHLdd?\u
Run Code Online (Sandbox Code Playgroud)
我用'fs'来创建一个图像文件.代码如下:
const options = {
url: "https://graph.microsoft.com/beta/me/photo/$value",
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${locals.access_token}`,
'Content-type': 'image/jpg',
}
};
request(options, (err, res, body) => {
if(err){
reject(err);
}
console.log(res);
const fs = require('fs');
const data = new Buffer(body).toString("base64");
// const data = new Buffer(body);
fs.writeFileSync('profile.jpg', data, (err) => {
if (err) {
console.log("There was an error writing the image")
}
else {
console.log("The file is written successfully");
}
});
});
Run Code Online (Sandbox Code Playgroud)
文件写入成功,但.jpg …
我按照https://www.digitalocean.com/community/tutorials/vuejs-screenshot-ui步骤使用 Vue.js 捕获屏幕截图。截图成功,但截图尺寸似乎不正确。
问题:
问题: -我认为,问题在于takeScreenshot方法
takeScreenshot: function () {
html2canvas(document.querySelector('body')).then(canvas => {
let croppedCanvas = document.createElement('canvas'),
croppedCanvasContext = croppedCanvas.getContext('2d');
croppedCanvas.width = this.boxEndWidth;
croppedCanvas.height = this.boxEndHeight;
croppedCanvasContext.drawImage(canvas, this.boxLeft, this.boxTop,
this.boxEndWidth, this.boxEndHeight, 0, 0, this.boxEndWidth,
this.boxEndHeight);
this.imageUrl = croppedCanvas.toDataURL();
const screenshotImg = document.getElementById('screenshotImg');
screenshotImg.src= this.imageUrl;
console.log('imageUrl', this.imageUrl)
});
}
Run Code Online (Sandbox Code Playgroud)
很想知道是否有修复或其他更好的截屏方式。谢谢你。
Codepen 链接:https ://codepen.io/dineshmadanlal/pen/MWjeXBQ