将 PNG 分层(HTML5、JS)

发布于 2024-11-17 00:41:55 字数 852 浏览 3 评论 0原文

我正在为一个小型非商业项目工作,我现在遇到的问题是脚本选取了一个 png 图像,但是当我导出它时,有两层,如何将此图像分为两个不同的层并在其加载到 convas 后对其进行操作?

<html>
<head>
    <title>test</title>
    <script type="text/javascript">
        function startup() {
            var canvas = document.getElementById('canvas');
            var ctx = canvas.getContext('2d');
            var img = new Image();
            img.src = 'brushes.png';
            img.onload = function() {
                ctx.translate(32, 120);
                ctx.rotate(40 * Math.PI/180);
                ctx.drawImage(img, -32, -120, 64, 120);
            }
        }
    </script>
</head>
<body onload='startup();'>
    <canvas id="canvas" style="position: absolute; left: 300px; top: 300px;" width="800" height="800"></canvas>
</body>

I'm working for a small non commercial project, what I'm stuck on right now is that the script picks up a png image, however when I exported it, there are two layers, how do I divide this image into two different layers and manipulate one once its loaded up into convas?

<html>
<head>
    <title>test</title>
    <script type="text/javascript">
        function startup() {
            var canvas = document.getElementById('canvas');
            var ctx = canvas.getContext('2d');
            var img = new Image();
            img.src = 'brushes.png';
            img.onload = function() {
                ctx.translate(32, 120);
                ctx.rotate(40 * Math.PI/180);
                ctx.drawImage(img, -32, -120, 64, 120);
            }
        }
    </script>
</head>
<body onload='startup();'>
    <canvas id="canvas" style="position: absolute; left: 300px; top: 300px;" width="800" height="800"></canvas>
</body>

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

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

发布评论

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

评论(1

冷弦 2024-11-24 00:41:55

据我所知 PNG 没有任何图层,因此您需要为每个图层保存一个图像才能单独操作它们。

As far as I know PNG does not have any layers, so you would need to save one image for each layer to manipulate them separately.

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