我一直在寻找,但我无法找到有效的CSV转换器的图像文件。你有某种语言的程序/代码/建议会输出类似的东西 1,1,255,255,255,0 1,2,255,0,255,0 这很容易理解。我认识Lua,但我很好用其他我不懂的语言来获得输出。
感谢。
我想这样做是因为我有一个平庸的分形地形生成脚本,只能在游戏(roblox)上使用他们的GUI显示,并且需要400k MB。在用地形填充之后,我宁愿加载一个快速的500x500 png文件。
答案 0 :(得分:0)
你可以使用Lua-GD,一个用于绘制C的gdlibrary的绑定。
您必须首先安装gd及其所有依赖项,然后安装Lua-GD,如manual所述。
以下是执行所请求的Lua代码:
require 'gd'
local f = io.open('file.csv', 'w')
local img = gd.createFromPng('image.png')
for y = 1, img:sizeY() do
local line = ''
for x = 1, img:sizeX() do
-- I'm not sure about the return of this function,
-- the documentation is unclear. But it should not
-- be very different.
local r, g, b = img:getPixel(x, y)
line = line .. r .. ', ' .. g .. ', ' .. b .. ', '
end
line = line:gsub(',$', '\n') -- remove last comma
f:write(line)
end
f:close()
请注意,为简单起见,不会进行任何错误处理。