I have PNG files and the Gloss library has a Bitmap
constructor for Picture
. I can't use loadBMP :: FilePath -> IO Picture
because of the filetype, so I'm searching how to load a PNG file, convert it to BMP, and feed it to either bitmapOfBMP :: BMP -> Picture
, bitmapOfForeignPtr :: Int -> Int -> ForeignPtr Word8 -> Bool -> Picture
or bitmapOfByteString :: Int -> Int -> ByteString -> Bool -> Picture
.
Test with 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
Everything succeeds but the image is not the same at all.
\_ -> id
is the same asconst id
. – huon Aug 31 '12 at 23:11