将 PNG 分层(HTML5、JS)
我正在为一个小型非商业项目工作,我现在遇到的问题是脚本选取了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知 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.