【问题标题】:EaselJS, create an image from a file (canvas)EaselJS,从文件(画布)创建图像
【发布时间】:2013-06-10 01:41:49
【问题描述】:

我正在尝试从 json 文件生成地图,并且正在使用框架 EaseIJS。

实际上,我有一个这样的 json:

[
        [ 1, 1, 0, 0, 0 ],
        [ 0, 0, 0, 0, 0 ],
        [ 0, 0, 1, 0, 1 ],
        [ 0, 0, 1, 0, 0 ],
        [ 0, 0, 0, 0, 1 ]
]

对于每个数字(图块),我可以生成一种颜色:

var tiles =
{
        0: function(){return new Tile ( TileType.DRAW, gfx.solTAlea(200,200,128), true );},
        1:null
};

在这个例子中,使用函数 solTAlea(),我生成了一个随机颜色的图块:

$color = Graphics.getRGB ( $r, $g, $b );
this.gfx = new Shape();
this.gfx.name = $color;
this.gfx.graphics.beginFill($color)
                  .moveTo(64,0)
                  .lineTo(0,-32)
                  .lineTo(-64,0)
                  .lineTo(0,32)
                  .lineTo(64,0)
                  .closePath();
return this.gfx;

这个回报的价值是我的瓷砖,具有特定的颜色。之后我可以在我的画布地图上绘制它。

但是如何从文件创建图像?我不需要生成随机颜色图块 ($color = Graphics.getRGB ($r, $g, $b);) 但我需要创建一个带有图像的图块,例如 png..

你有什么想法吗?对于这个例子,我使用函数 Shape() 来创建图块。

谢谢!

【问题讨论】:

  • 我不完全确定您想要实现什么 - 您想将画布的内容保存到可以下载的 png 格式吗?

标签: json canvas map easeljs


【解决方案1】:

您好,您可以简单地使用 Bitmap 类:

 var image = new createjs.Bitmap("image.png");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2013-05-14
    • 2016-07-04
    • 1970-01-01
    • 2019-05-18
    相关资源
    最近更新 更多