简体   繁体   中英

Improving Canvas Performance with Transparency

Drawing images that contain transparency is slow.

Is there any way of just discarding the pixels that contain transparency?

When I draw images that do not contain any transparent pixels, it's really fast.

Yup, you can obtain a context with no alpha support. the slowness is likely coming from the background compositing the browser have to do with the element and each time something is drawn. here's how (notice the option at the end)

var context = canvas.getContext('2d', {alpha:false});

you can still composite transparency locally inside the canvas but the background will always stay opaque. i think most browsers support it but i wouldn't hold onto my hat for ie11 or older.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM