我想从选定区域到OS缓冲区的canvas(如画家)中实施ctrl + c事件。基于this的答案我可以添加copy
监听器并将剪贴板数据更改到那里 - 这与文本完美配合。但是我找不到如何将Image
/ImageData
对象放在那里。这里是MDN copy文档和setData。似乎没有什么关于image/*
格式。那么Specification也没有说什么。但我闻到,如果第一个参数在setData
中命名为format
,那么应该有办法将文件放在那里。如何在oncopy事件中将图像设置为剪贴板数据
此处,我走了这么远:
document.addEventListener('copy', function(e) {
var data = ctx.getImageData(params.left, params.top, params.width, params.height);
var file = new File(data.data, "file.png", {type: "image/png"});
e.clipboardData.items.add(file, 'image/png'); // This doesn't work, But it create the structure like on the image below(with items and types, but without FileList)
e.clipboardData.setDragImage(tool.img, 10, 10); // doesn't work
e.clipboardData.setData("image/png", tool.file); // doesn't work
e.preventDefault();
})
我还发现setDragImage方法,我实现了,但把Image
后它不会出现在缓冲区中。
注:
当我粘贴图像FROM我的剪贴板“粘贴”事件显示事件结构像图像波纹管,所以我想我需要创建类似的东西。
任何想法?
p.s.我也知道document.execCommand('copy');,但它不适用于chrome(至少在我的情况下),所以我不想使用它。