In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to optimize the performance of HTML5 Canvas procedures related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to optimize the performance of HTML5 Canvas procedures will have a harvest, let's take a look.
[use caching]
Using cache is to pre-render with off-screen canvas, the principle is very simple, that is, first draw to an off-screen canvas, and then draw the off-screen canvas to the main canvas through drawImage. If you see this, many people will misunderstand, isn't this the double buffering mechanism used in writing games?
In fact, the double buffering mechanism is to prevent the screen from flickering in game programming, so there will be a canvas displayed in front of the user and a background canvas. When drawing, the content of the picture will be drawn to the background canvas, and then the data in the background canvas will be drawn to the foreground canvas. This is double buffering, but there is no double buffering in canvas, because modern browsers basically have a built-in double buffering mechanism. Therefore, the use of off-screen canvas is not a double buffer, but an off-screen canvas as a cache area. The screen data that needs to be drawn repeatedly is cached to reduce the consumption of API calling canvas.
As we all know, calling the API of canvas consumes a lot of performance, so when we want to draw some repetitive picture data, making good use of the off-screen canvas can greatly improve the performance, you can take a look at the following DEMO
1. No cache is used
2. Cache is used but the width and height of off-screen canvas is not set.
3. Cache is used but the width and height of off-screen canvas is not set.
4. Cache is used and the width and height of off-screen canvas is set.
You can see that the performance of the above DEMO is different, the following analysis of the reasons: in order to achieve the style of each circle, so I used a loop to draw circles, if not enabled cache, when the number of circles on the page reached a certain number, animation every frame will be a large number of calls to canvas API, to do a lot of calculation, so that the best browser will be dragged down.
XML/HTML Code copies content to the clipboard
Ctx.save ()
Var jung0
Ctx.lineWidth = borderWidth
For (var iTunes 1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.