【发布时间】:2012-08-31 21:33:26
【问题描述】:
我有 PNG 文件,the Gloss library 有一个用于 Picture 的 Bitmap 构造函数。由于文件类型,我不能使用loadBMP :: FilePath -> IO Picture,所以我正在搜索如何加载PNG文件,将其转换为BMP,并将其提供给bitmapOfBMP :: BMP -> Picture、bitmapOfForeignPtr :: Int -> Int -> ForeignPtr Word8 -> Bool -> Picture或bitmapOfByteString :: Int -> Int -> ByteString -> Bool -> Picture。
使用 JuicyPixels 进行测试
import Data.ByteString as B
import System.IO as A
import Codec.Picture.Png
import Graphics.Gloss.Interface.Pure.Game
main = do
png <- B.readFile "samus.png"
let img = decodePng png
case img of
Left x -> A.putStrLn x
Right x -> do
let bmp = encodeDynamicPng x
case bmp of
Left x -> A.putStrLn x
Right x -> do
let pic = bitmapOfByteString 29 52 x True
game pic
game pic
= play
(InWindow "Test" (700, 500) (10, 10))
white
30
pic
draw
(const id)
(const id)
draw bmp
= bmp
一切都成功了,但图像完全不一样。
【问题讨论】:
-
另外,作为文体观点,请注意
\_ -> id与const id相同。 -
为了它的价值,我为此写了gloss-juicy。
-
太好了,看起来更完整了;我会试试你的包裹!对于大多数严肃的 Gloss 项目来说,这绝对是必须的。