简体   繁体   English

如何使用html2canvas获取图像的屏幕截图?

[英]How can I get screenshot of image using html2canvas?

I am trying to save screenshot of image using html2canvas. 我试图使用html2canvas保存图像的屏幕截图。 Below is my code: 以下是我的代码:

        var a = document.getElementById('a2')
        html2canvas(document.getElementById('a1'), {
            onrendered: function(canvas) {
            var img = canvas.toDataURL("image/jpeg");
            window.open(img);
                    }
        }

However, the code is saving the screenshot for local image. 但是,代码正在保存本地图像的屏幕截图。 But for the image from external source like : http://europa.promaticstechnologies.com/QuotePic/img/QuotePro/bg1.jpg giving me black screenshot. 但对于外部来源的图像,如: http//europa.promaticstechnologies.com/QuotePic/img/QuotePro/bg1.jpg给我黑色截图。 Please assist. 请协助。

To use image from external domain you may want to use crossOrigin attribute and current Date as a parameter to src attribute. 要使用外部域中的图像,您可能希望使用crossOrigin属性和当前日期作为src属性的参数。

eg 例如

var image = document.createElement('img');
image.onload = function () {
// onload callback
}
image.setAttribute('crossOrigin', '');
image.src = url + '?' + new Date().getTime();

Check this for details. 检查了解详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM