-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
putImageData is not drawing anything in the canvas #180
Comments
|
Reason I'm not using new ImageData(...) is that it gives me error: This error is related to https://stackoverflow.com/questions/38556730/imagedata-byte-length-is-not-a-multiple-of-4-width which says length of Uint8ClampedArray needs to be the multiple of width, height and 4. In my image case 612480 / (480 * 319 * 4) = 1 so it's fine but it still gives me the error. @iddan |
Anyways my expectation is that given the following input: (An ImageData given from another source) putImageData should work as expected but it gives the following error: Because it's not an initialized ImageData from new ImageData/createImageData.
|
My workaround is to initialize with new ImageData(...) and then add the properties to the instance.
That way I get the desired ImageData instance with the proper data, but putImageData still does nothing to the canvas. (Nothing is drawn) Did someone get putImageData working before? |
I think I made something work. I have one canvas Acoording to my research, the important thing is that the ImageData you draw on a canvas has a reference to that canvas. const drawingData = await drawCanvas
.getContext('2d')
.getImageData(0, 0, drawCanvas.width, drawCanvas.height);
const data = Object.values(drawingData.data);
const newImageData = new ImageData(
canvas2,
data,
drawCanvas.width,
drawCanvas.height,
);
context2.putImageData(newImageData, 0, 0); |
Thank You, Sir. This way solve my problem! |
canvasContext.putImageData(data,0,0) not drawing anything
I'm trying to pass an ImageData element to the canvas so it's displayed on it, my code looks like:
Outputs:
encodedImage is a black and white ImageData mask from https://www.npmjs.com/package/@tensorflow-models/body-pix#returns-4
Canvas is that red box:
Nothing is painted inside when using putImageData with Outputs data.
If I try to pass the ImageData to another canvas context I get the following error: Error: Argument 1('imagedata') to CanvasRenderingContext2D.putImageData must be an instance of ImageData
The text was updated successfully, but these errors were encountered: