In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you HTML5 Canvas how to achieve picture scaling, I hope you have something to gain after reading this article, let's discuss it together!
Another variation of the drawImage method is the addition of two parameters to control the scaling of the image in canvas.
DrawImage (image, XBI y, width, height)
Where width and height are the size of the image displayed in the canvas, respectively.
Note: the image may become cluttered or blurred due to large zooming. If you have text in your image, it is best not to zoom, as it is likely that the text in the image will become illegible after processing.
Picture zooming example
Description
In this example, I will use a picture to repeat it on the canvas like a background. It is also easy to implement, simply by cycling out the zoomed image. See the code below, the first layer image size is scaled to the original expansion, 50x38 pixels. For the loop is to repeat the row, and the second layer is to repeat the column.
Note: there is still a certain gap between the pictures in this example, and we don't know how to remove them yet.
Code
< html > < meta http-equiv = " Content-Type" content = " text / html; charset = utf-8" />Function draw () {
Var ctx = document.getElementById ('canvas'). GetContext (' 2d')
Var img = new Image ()
Img.onload = function () {
For (I = 0; I)
< canvas id = " canvas"宽度= " 400" height = " 300" > < / /帆布>After reading this article, I believe you have a certain understanding of "how to achieve picture scaling in HTML5 Canvas". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.