question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

drawImage and getImageData does not execute

See original GitHub issue

render:

<View style={{flex: 1}}>
    <Canvas 
        ref={ref => {
        this.tempCanvas = ref;
    }}/>
.....
</View>
ImagePicker.launchImageLibrary({
    mediaType: 'photo',
        //allowsEditing: true,
    }, (response) => {
        if(!response.didCancel) {
            console.log(response);
            this.tempCanvas.width = response.width;
            this.tempCanvas.height = response.height;

            const ctx = this.tempCanvas.getContext('2d');
            ctx.drawImage(`data:${response.type};base64,${response.data}`, 0, 0, response.width, response.height);
            console.log(`data:${response.type};base64,${response.data}`);
            ctx.getImageData(0,0,response.width,response.height)
                .then(imageData => {
                    // does not execute
                    console.log(imageData);
                }).catch(error => {
                    //does not execute
                    console.log(error);
                });
        }
    });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Tanatcucommented, Feb 28, 2019

If @iddan don’t mind I will deal with warnings in the next pull request. About drawImage. You should use Image class from library. How? You can check it in file example/App.js. What problem/error/exception do you have with getImageData?

0reactions
zuntilZcommented, Jun 23, 2020

I want to use the canvas to get the image pixel data, use jsqr to decode QR codes.

Ok, I solved this problem with jpeg-js.

Can you describe clearly whether the problem is resolved ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

canvas context getImageData() function won't execute ...
javascript - canvas context getImageData() function won't execute, probably because it's executed before the image is loaded - Stack Overflow. ...
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 getImageData() Method - W3Schools
The getImageData() method returns an ImageData object that copies the pixel data for the specified rectangle on a canvas. Note: The ImageData object...
Read more >
68568 - Canvas: SOP error when using getImageData after ...
One would expect to be able to draw an SVG image into a canvas using drawImage and then be able to read the...
Read more >
Does getImageData not work in IE at all? - Google Groups
just up a river with no paddle? ... var canvasContext = canvas.getContext( '2d' ); canvasContext.drawImage( _image, 0, 0 ); // the next line...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found