Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.17k stars 1.17k forks source link

Cloning ImageData #610

Closed inssein closed 9 years ago

inssein commented 9 years ago

I can't figure out how to clone an ImageData object, short of retrieving it again from the context.

All the methods I know of require ImageData.data to be a Uint8ClampedArray with the setter exposed. Is there anything I can do right now, short of waiting for https://github.com/Automattic/node-canvas/pull/604 to be merged?

LinusU commented 9 years ago

There is putImageData, or am I misunderstanding what it is you want to do?

inssein commented 9 years ago

@LinusU I wanted to clone ImageData, and then perform some operations.

Example: https://github.com/inssein/jsfx/blob/master/src/filter/unsharpMask.ts#L75

LinusU commented 9 years ago

Shouldn't that code work as is right now?

inssein commented 9 years ago

@LinusU works on the web, doesn't seem to properly clone in node-canvas. Also, shouldn't it be a CanvasPixelArray right now, before the PR is merged?

inssein commented 9 years ago

Sorry, the issue was with something else. new Uint8ClampedArray(imageData.data) seems to clone the data just fine.