我正在玩,Graphics.GD
我想将图像读入Color
值矩阵,有点像这样:
rectFromImage :: Image -> IO [[Color]]
rectFromImage img = do
size <- imageSize img
return [[getPixel (x,y) img | x <- [1 .. fst size]] | y <- [1 .. snd size]]
显然,这不起作用,因为getPixel
返回IO Color
,而不是Color
:
Couldn't match type `IO Color' with `Foreign.C.Types.CInt'
Expected type: Color
Actual type: IO Color
In the return type of a call of `getPixel'
In the expression: getPixel (x, y) img
In the expression: [getPixel (x, y) img | x <- [1 .. fst size]]
在调用返回时如何“摆脱 IO” getPixel
?