我有PNG文件,Gloss库有一个
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
是相同的。 - huon