js浏览器截图的的方法

screenShots: function () {
// parent.window.frames[0].frameElement.contentWindow.camera();
// Ext.getCmp(‘mainViewPort’).getEl().mask(“文件保存中,请稍候…”);
PublicObject.fileType = ‘image’;
// parent.window.frames[0].frameElement.contentWindow.$(’#screenshot’).trigger(‘click’);
// var video = parent.window.frames[0].frameElement.contentWindow.document.getElementById(“remote-video”);
var video = parent.window.frames[0].frameElement.contentWindow.getVideoElement();
var canvas = parent.window.frames[0].frameElement.contentWindow.document.createElement(“canvas”);
var ctx = canvas.getContext(“2d”);
var width = video.videoWidth;
var height = video.videoHeight;
canvas.width = width;
canvas.height = height;
ctx.drawImage(video, 0, 0, width, height);
ctx.font = “bold 32px microsoft yahei”;
ctx.fillStyle = “orangered”;
ctx.fillText(“PICC”, width - 90, height - 60);
ctx.font = “12px microsoft yahei”;
ctx.fillStyle = “rgb(255,255,255)”;
ctx.fillText(PublicObject.CurrentTaskData.registno, width - 140, height - 40);
var now = formatDate(new Date, “yyyy-MM-dd hh:mm:ss”);
ctx.fillText(now, width - 130, height - 25);
ctx.fillText(PublicObject.CurrentUser.jobno, width - 68, height - 10);
var imgData = canvas.toDataURL(“image/jpg”);

    // $('#ImgWrap').html('')    //将截图展示在右侧
    // $('#ImgWrap').css({ 'background-image': imgData, 'background-size': 'contain' });
    $('#ImgWrap').html('');
    $('.screenImg').attr('src', imgData);
    $('#CloseScreenIMg').show();

    var blob = dataURItoBlob(imgData);
    var mimeString = imgData.split(",")[0].split(":")[1].split(";")[0];
    var registno = PublicObject.CurrentTaskData.registno;
    var now = (new Date).getTime();
    var filename = registno + "_" + now + ".jpg";
    PublicObject.fileName = filename;
    var a = document.createElement("a");
    a.href = imgData;
    a.download = filename;
    var event = document.createEvent("MouseEvents");
    event.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(event);

    // 保存图片到浏览器
    // parent.window.frames[0].frameElement.contentWindow.savePicToBrowser();
},

你可能感兴趣的:(js浏览器截图的的方法)