function transform(b64Image) {
const img = atob(b64Image.split(',')[1]);
const image = [];
let i = 0;
while (i < img.length) {
image.push(img.charCodeAt(i));
i++;
}
return new Uint8Array(image);
}
var b64Image = canvas.toDataURL('image/jpeg');
var u8Image = transform(b64Image);
var formData = new FormData();
formData.append("image", new Blob([ u8Image ], {type: "image/jpg"}));
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upimage", true);
xhr.send(formData);
HTML5 Canvas转化成图片后上传服务器
最新推荐文章于 2023-08-10 18:04:53 发布