【发布时间】:2019-08-14 00:44:30
【问题描述】:
我正在尝试使用 Erlang wxImage 库在 Elixir 中操作“test.jpg”图像,但出现错误。我不知道如何将数组/常量输出转换为列表,以便我可以在 Elixir 中使用它。
另外我不知道为什么语法似乎没问题的时候会出现子句函数错误?
defmodule Imedit2 do
def readimg(image) do
{:ok, _file} = File.open("happy737.txt", [:write])
IO.puts("hi there")
_output =
image
|> File.read!()
|> :wxImage.getData()
|> to_charlist()
# IO.puts(is_list(output))
# IO.puts(is_tuple(output))
# IO.binwrite(file, output)
# File.close(file)
end
end
iex(58)> Imedit2.readimg("test.jpg")
hi there
** (FunctionClauseError) no function clause matching in :wxImage.getData/1
The following arguments were given to :wxImage.getData/1:
# 1
<<255, 216, 255, 226, 2, 28, 73, 67, 67, 95, 80, 82, 79, 70, 73, 76, 69, 0, 1,
1, 0, 0, 2, 12, 108, 99, 109, 115, 2, 16, 0, 0, 109, 110, 116, 114, 82, 71,
66, 32, 88, 89, 90, 32, 7, 220, 0, 1, 0, 25, ...>>
gen/wxImage.erl:405: :wxImage.getData/1
lib/imedit2.ex:5: Imedit2.readimg/1
【问题讨论】:
-
您将二进制文件传递给函数
:wxImage.getData/1。如果您查看该函数的documentation,它期望引用图像,而不是图像二进制数据。我以前从未使用过这个库,但看起来您需要调用:wxImage.loadFile/{2,3,4}才能从文件加载图像。您可能还需要调用new/0函数来首先获取空白图像参考。 -
我认为 File.read 会加载图像,这就是为什么 wximage 处理加载的图像会输出数字的原因。