如何绘制调整大小的图片而不是线条? (html5画布)

发布于 2024-10-08 20:20:57 字数 322 浏览 0 评论 0原文

因此,我们可以使用这样的函数来绘制一条线

function drawLine(g, n, x1, y1, x2, y2){
    g.beginPath();
    g.lineWidth = n > 0 ? n : 1;
    g.strokeStyle = "rgb(0, 128, 32)";
    g.moveTo(x1, y1);
    g.lineTo(x2, y2);
    g.stroke();
}

,但是如果我们想绘制图像而不是线(根据线的大小调整大小,使用 alpha 通道)怎么办?

这样的事该怎么办呢?

So we can have for example such function to draw a line

function drawLine(g, n, x1, y1, x2, y2){
    g.beginPath();
    g.lineWidth = n > 0 ? n : 1;
    g.strokeStyle = "rgb(0, 128, 32)";
    g.moveTo(x1, y1);
    g.lineTo(x2, y2);
    g.stroke();
}

but what if we want to draw an image instead of line (resized in respect for line size, with alpha channel).

How to do such thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ左 2024-10-15 20:20:57

使用上下文的 drawImage() 方法,但首先translate、旋转缩放上下文。图像将显示为一条根据您的喜好旋转的细长线。

编辑:我已经在网上发布了此技术的实时示例,将技术包装成一个函数。

Use the drawImage() method of the context, but first translate, rotate, and scale the context. The image will come out as a long thin line rotated as you like.

Edit: I've put a live example of this technique online, wrapping the technique up as a function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文