我想在单击按钮时通过按钮将画布显示复制到剪贴板,但是我找不到任何方法。我试图复制文本,这样做很容易。有人告诉我如何将画布显示复制到剪贴板吗? 这是我的代码,但是代码将图像复制并粘贴到我要保存图像或所有画布显示在剪贴板上的屏幕上。
function copyImage() {
var imgCap = document.getElementById('imgCap');
var imgCanvas = document.createElement('canvas');
imgCanvas.id = 'imgCanvas';
//imgCanvas.height = 40;
// imgCanvas.width = 120;
document.body.appendChild(imgCanvas);
var originalContext = imgCanvas.getContext('2d');
originalContext.drawImage(imgCap, 0, 0);
// event.clipboardData.setData('img', imgCap);
// var data = window.clipboardData.setData("image / svg + xml", imgCap);
//window.clipboardData.setData
return imgCanvas.toDataURL();
}
<!DOCTYPE html>
<html lang="en" xmlns="cathid.bmp">
<head>
<meta charset="UTF-8">
<title>Mohamed Higab </title>
<link href="new.css" rel="stylesheet">
<script src="Script1.js"></script>
</head>
<body>
<img id="imgCap" src="cathid.bmp" />
<button type="button" class="btn" onclick="copyImage();">copy</button>
</body>
</html>