gpt4 book ai didi

javascript - 是否可以更改 Canvas 的位置而不是重新绘制图片?

转载 作者:行者123 更新时间:2023-12-02 14:33:58 25 4
gpt4 key购买 nike

假设我想将两个图像的 X 坐标向右 move 2。

而不是这样做:

drawImage(image1, x1, y1, imageWidth1, imageHeight1);
drawImage(image2, x2, y2, imageWidth2, imageHeight2);

ctx.clearRect(0, 0, c.width, c.height);

drawImage(image1, x1 + 2, y1, imageWidth1, imageHeight1);
drawImage(image2, x2 + 2, y2, imageWidth2, imageHeight2);

可以做这样的事情吗?

drawImage(image1, x1, y1, imageWidth1, imageHeight1);
drawImage(image2, x2, y2, imageWidth2, imageHeight2);
moveCanvas(2, 0); //This moves the canvas entirely +2 to the right
//without the need of redrawing

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Title</title>
</head>
<body>
<canvas id = "canvas"
style="z-index: 1;
position:absolute;
left:0px;
top:0px">
</canvas>
</body>
</html>

最佳答案

嗯...你可以 move 放置 Canvas 的容器,并获得相同的结果

关于javascript - 是否可以更改 Canvas 的位置而不是重新绘制图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com