Skip to content
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

Speed up canvas rendering using putImageData #5

Closed
dazuma opened this issue Feb 8, 2012 · 2 comments
Closed

Speed up canvas rendering using putImageData #5

dazuma opened this issue Feb 8, 2012 · 2 comments
Assignees

Comments

@dazuma
Copy link

dazuma commented Feb 8, 2012

Hi,

I had actually written something similar for one of my projects. Just wanted to pass on a suggestion based on what I had done.

Currently, you're rendering by calling context.fillRect() for each pixel. This can actually get quite slow. You might consider manipulating an ImageData directly. Call context.createImageData() to get an offscreen ImageData object. Then you can set pixels simply by setting rgba values in the data array. Finally, render the entire image back to the canvas using context.putImageData(). It generally turns out many, many times faster than the thousands of fillRect calls.

The downside is that you can't use the css-like syntax to set colors; you have to set raw rgba values numerically. But it may be a worthwhile trade-off.

@ghost ghost assigned sunng87 Feb 9, 2012
@sunng87
Copy link
Owner

sunng87 commented Feb 9, 2012

Thank you very much !

The performance of HeatCanvas has been there for a long time. I will create a branch to apply your suggestion.

@sunng87
Copy link
Owner

sunng87 commented Feb 11, 2012

Thank you for you suggestion. The enhancement has been merged into master.

@sunng87 sunng87 closed this as completed Feb 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants