This is working, but I feel this code is lengthy. I'm looking for better idea.
var clone = function(imageData) {
var canvas, context;
canvas = document.createElement('canvas');
canvas.width = imageData.width;
canvas.height = imageData.height;
context = canvas.getContext('2d');
context.putImageData(imageData, 0, 0);
return context.getImageData(0, 0, imageData.width, imageData.height);
};
The ImageData interface represents the underlying pixel data of an area of a <canvas> element. It is created using the ImageData() constructor or creator methods on the CanvasRenderingContext2D object associated with a canvas: createImageData() and getImageData() .
The getImageData() method returns an ImageData object that copies the pixel data for the specified rectangle on a canvas.
The ImageData constructor accepts the image data array.
const imageDataCopy = new ImageData(
new Uint8ClampedArray(imageData.data),
imageData.width,
imageData.height
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With