我刚开始学习 Haskell,所以我可能遗漏了一些非常琐碎的东西。我正在尝试使用 Haskell 图像处理生成图像。我正在从文档的示例片段中调整代码。我的代码如下。
{-# LANGUAGE NoImplicitPrelude #-}
module Main where
import Prelude as P
import Graphics.Image as I
getPixel :: (Int, Int) -> Pixel RGB Word8
getPixel (i, j) = PixelRGB (fromIntegral i) (fromIntegral j) (fromIntegral (i + j))
getImage :: (Int, Int) -> Image VS RGB Word8
getImage (w, h) = makeImageR VS (w, h) getPixel
main :: IO ()
main = writeImage "image.png" image
where image = getImage (1024, 1024)
当我尝试构建它时,我得到以下信息
• No instance for (Writable (Image VS RGB Word8) OutputFormat)
arising from a use of ‘writeImage’
• In the expression: writeImage "image.png" image
In an equation for ‘main’:
main
= writeImage "image.png" image
where
image = getImage (1024, 1024)
似乎无法弄清楚我做错了什么。