konvajs / react-konva

React + Canvas = Love. JavaScript library for drawing complex canvas graphics using React.
https://konvajs.github.io/docs/react/
MIT License
5.8k stars 260 forks source link

Uncaught TypeError: getImage.crop is not a function #783

Open TruongNoDame opened 11 months ago

TruongNoDame commented 11 months ago

The code I get this error is: const crop = imageSrc.crop({ x: value.x / ratio_w, y: value.y / ratio_h, width: value.width / ratio_w, height: value.height / ratio_h }); I got this error when I was trying to get a subimage with the x,y, width and height coordinates of the image area to get. In there I declare const [imageSrc, setImageSrc] = useState(null), and I update the value of imageSrc here:

const handleImageChange = (event) => {
         const file = event.target.files[0];
         if (file) {
             const reader = new FileReader();
             reader.onloadend = () => {
                 setImageSrc(reader.result)
             };
             reader.readAsDataURL(file);
         }
     };

According to Konva's documentation, there are instructions:

/ get crop
var crop = image.crop();