簡體   English   中英

在畫布上繪制時使用setTransform有什么好處?

[英]What are the benefits of using a setTransform for when drawing on a Canvas?

我仍然不確定甚至不確定setTransform的功能。 我在互聯網上找到了此代碼示例,並一直在弄亂它,以查看對setTransform所做的不同更改。 使用setTransform變量的真正用途和好處是什么,而不是僅繪制一個新的矩形。

問題:使用setTransform有什么好處和用途?

碼:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

ctx.fillStyle="yellow";
ctx.fillRect(0,0,125,50)

ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="red";
ctx.fillRect(0,0,250,100);

ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="blue";
ctx.fillRect(0,0,250,100);

</script>

畫布上的每個對象都有一個當前的轉換矩陣。

setTransform()方法將當前轉換重置為單位矩陣,然后使用相同的參數運行transform()。

換句話說,使用setTransform()方法可以縮放,旋轉,移動和傾斜當前上下文。

注意:轉換只會影響在調用setTransform方法之后制作的圖形。

資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM