我有 PNG 文件,光泽库有一个Bitmap
用于Picture
. 由于文件类型,我无法使用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
一切都成功了,但图像根本不一样。