Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image JuicyPixels可以';无法加载PNG文件_Image_Haskell_Juicy Pixels - Fatal编程技术网

Image JuicyPixels可以';无法加载PNG文件

Image JuicyPixels可以';无法加载PNG文件,image,haskell,juicy-pixels,Image,Haskell,Juicy Pixels,我正在尝试学习如何使用JuicyPixels版本3.2.5.1加载、修改和保存图像。我有以下代码: {-# LANGUAGE OverloadedStrings #-} import Codec.Picture imageCreator :: String -> IO () imageCreator path = writePng path $ generateImage pixelRenderer 250 300 where pixelRenderer x y = PixelR

我正在尝试学习如何使用JuicyPixels版本3.2.5.1加载、修改和保存图像。我有以下代码:

{-# LANGUAGE OverloadedStrings #-}

import Codec.Picture

imageCreator :: String -> IO ()
imageCreator path = writePng path $ generateImage pixelRenderer 250 300
   where pixelRenderer x y = PixelRGB8 (fromIntegral x) (fromIntegral y) 128

loadSampleImage path = case decodePng path of
  Left errorMsg -> putStrLn errorMsg
  Right sampleImage -> putStrLn "Loaded Successfully"

main = do 
  imageCreator "test.png"
  loadSampleImage "test.png"
imageCreator
函数是从JuicyPixels文档中稍加修改而来的:修改是添加了对
fromIntegral
的两个调用,因为没有它们,本例无法编译。(文档中的一个示例无法编译,这对我来说似乎很奇怪,因此如果我正在做一些愚蠢的事情,请让我知道)

运行此程序将创建一个名为“test.png”的图像,并将打印:

无效的PNG文件,签名已损坏

这可能是调用
decodePng
时发出的错误消息。我已经尝试了其他一些PNG,一个是我在Gimp中创建的,另一个是我在MS paint中创建的。为此,我从主函数中删除了
imageCreator“test.png”
行,以避免覆盖我想要测试的图像

要加载PNG图像,我应该更改什么

您试图将字符串“test.png”解码为png。您想要的是
readPng
,而不是
decodePng
。(或者您可以只使用
readImage
,而不关心文件的格式。)

您试图将字符串“test.png”解码为png。您想要的是
readPng
,而不是
decodePng
。(或者您可以只使用
readImage
,而不关心文件的格式。)

loadSampleImage path = case decodePng path of