我对 Haskell 的经验很少,我想写一个简单的光线追踪器来练习。因为我不想使用 wxHaskell 之类的 GUI 工具(我认为学习如何使用它们需要很多时间),所以我决定简单地将输出图像保存为 BMP 文件。但是我这里有个问题:
module Main where
import Codec.BMP
import qualified Data.ByteString as BS
main = do
Right bmp <- readBMP "grass.bmp"
BS.putStrLn $ BS.take 4 $ unpackBMPToRGBA32 bmp
在这里,我只想获取图像的第一个像素并打印其 RGBA 值。但我得到一个错误说
Couldn't match expected type `BS.ByteString'
with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
In the return type of a call of `unpackBMPToRGBA32'
In the second argument of `($)', namely `unpackBMPToRGBA32 bmp'
In the second argument of `($)', namely
`BS.take 4 $ unpackBMPToRGBA32 bmp'
我究竟做错了什么?如何获取图像的像素并打印它们的值?