how to get rgb values of image in fabric.js on mouse move. I used getFill() method of image object, but it is returning (0,0,0). Please help me
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
FabricJS does not have a native method for getting the pixel colors.
The workaround is to use native html5 canvas to fetch the pixel data:
Create your Fabric image objects. Be sure to specify
crossOrigin
as 'anonymous' otherwise the canvas will be tainted with a security violation and then the pixel data will be unavailable.Listen on Fabric's 'mouse:move' event. When it fires, get the current mouse position and use native canvas's
context.getImageData
to fetch that pixel's color array.Good luck with your project!
Here's annotatede code and a Demo: