I would like to paste an image (which is currently in my clipboard) to a certain canvas. This paste-operation shall happen once I clicked a specific button on my page. There are two different routes to go:
- Once the user clicked a button, fire an onPaste event, use the image as a blob and paste it on my canvas
- After clicking the button, the js code reads the blob from the clipboard and paste it again on the canvas
I already played around window.clipboardData.getData
or navigator.Clipboard
, but none of them worked. Any hints?
I use the following code to visualize my blob image:
if(imageBlob){
var canvas = document.getElementById("mycanvas");
var ctx = canvas.getContext('2d');
var img = new Image();
img.onload = function(){
canvas.width = this.width;
canvas.height = this.height;
ctx.drawImage(img, 0, 0);
};
var URLObj = window.URL || window.webkitURL;
img.src = URLObj.createObjectURL(imageBlob);
}