如何将图像文件源转换为 CSV?

发布于 2024-12-26 10:59:33 字数 260 浏览 1 评论 0原文

我一直在寻找,但找不到可用的图像文件到 CSV 转换器。您是否有某种语言的程序/代码/建议可以向我输出类似的内容 1,1, 255,255,255, 0 1,2, 255,0,255, 0 这很容易理解。我了解 Lua,但我可以使用我不明白的其他语言来获取输出。

谢谢。

我想这样做是因为我有一个平庸的分形地形生成脚本,只能在带有 GUI 的游戏(roblox)上显示,并且需要 400k MB。在用地形内容编写之后,我更愿意加载一个快速的 500x500 png 文件。

I've been looking, but I cannot find an image file to CSV converter that works. Do you have a program/code/suggestion in some language that will output me something similar to
1,1, 255,255,255, 0
1,2, 255,0,255, 0
that is easy to understand. I know Lua, but I'm fine using other languages I don't understand to get the output.

Thanks.

I'd like to do this because I have a mediocre fractal terrain generation script that can only be displayed over a game(roblox) with their GUIs, and takes 400k MB. I'd much rather load a quick 500x500 png file, after writing it with the terrain stuff.

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

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

发布评论

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

评论(1

人│生佛魔见 2025-01-02 10:59:34

您可以使用 Lua-GD,它是 C 语言 gdlibrary 的绑定,用于绘图。

您必须首先安装 gd 及其所有依赖项,然后安装 Lua-GD,如 手册 说。

以下是执行所请求操作的 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()

请注意,为简单起见,未进行任何错误处理。

You can use Lua-GD, a binding for C's gdlibrary for drawing.

You must first install gd and all it's dependencies, then install Lua-GD, as the manual says.

Here is the Lua code to do what is requested:

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(',

Note that, for simplicity, no error handling is done.

, '\n') -- remove last comma f:write(line) end f:close()

Note that, for simplicity, no error handling is done.

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