putImageData is not drawing anything in the canvas
See original GitHub issuecanvasContext.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:
import Canvas, {ImageData} from 'react-native-canvas';
...
const handleCanvas = async canvas => {
canvas.width = sizes.width;
canvas.height = sizes.height;
const ctx = canvas.getContext('2d');
const data = await ctx.createImageData(
encodedImage.width,
encodedImage.height,
encodedImage.data,
);
console.log(
'data',
data,
data instanceof ImageData,
'encoded',
encodedImage,
encodedImage instanceof ImageData,
);
await ctx.putImageData(data, 0, 0);
};
...
{encodedImage && (
<Canvas
ref={handleCanvas}
style={{borderWidth: 1, borderColor: 'red', zIndex: 1000000}}
/>
)}
Outputs:
![Screenshot 2020-04-23 at 12 09 49](https://user-images.githubusercontent.com/45363951/80087859-fe1c3100-855b-11ea-9bfc-dee11a80a851.png)
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:
![Screenshot 2020-04-23 at 12 27 56](https://user-images.githubusercontent.com/45363951/80089289-f6f62280-855d-11ea-9fae-1748b3a2a940.png)
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Why does Canvas's putImageData not work when I specify ...
The height to use to draw the image on the canvas. As Loktar states above, the CORRECT synopsis is as follows: Correct Synopsis:...
Read more >CanvasRenderingContext2D.putImageData() - Web APIs | MDN
The CanvasRenderingContext2D.putImageData() method of the Canvas 2D API paints data from the given ImageData object onto the canvas.
Read more >HTML canvas putImageData() Method - W3Schools
The putImageData() method puts the image data (from a specified ImageData object) back onto the canvas. ... The width to use to draw...
Read more >Canvas putImageData does not work with GPU Accelerated ...
Issue 68495 : Canvas putImageData does not work with GPU Accelerated Canvas ... when canvas A was not visible, it would not draw...
Read more >Ejecta getImageData() and putImageData() Problem - ImpactJS
For some reason, putImageData will not display the image regularly. ... The thing with drawing though, is that you have to do it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 am also facing bug with![image](https://user-images.githubusercontent.com/8807496/81901306-2b646980-9573-11ea-88f9-7145ce2bb22d.png)
putDataImage
. When I run example app without any changes, it renders differently on different platforms. Check top left rectangle in two images below, one is from an emulator and one is from real phone. However, both are rendering wrong. If code was behaving correctly, entire top left rectangle would have been black.