Skip to content

Instantly share code, notes, and snippets.

@Capital-EX
Created December 6, 2017 22:23
Show Gist options
  • Save Capital-EX/c4e6144a29b89e8e604cfdae6499d0b7 to your computer and use it in GitHub Desktop.
Save Capital-EX/c4e6144a29b89e8e604cfdae6499d0b7 to your computer and use it in GitHub Desktop.
Functions to conver a DynamicImage (JuicyPixel) to a BMP (bmp) to us in Gloss
import qualified Data.ByteString.Lazy as BLazy
import Data.Bifunctor
import Graphics.Gloss
import Graphics.Gloss.Data.Picture
import Codec.Picture
import Codec.BMP
parseBMP :: BLazy.ByteString -> Either String BMP
parseBMP b = first show (parseBMP b)
loadPng :: FilePath -> IO Picture
loadPng fileName = do
result <- readImage fileName
case result >>= encodeDynamicBitmap >>= parseBMP of
Left error -> do
putStrLn error
pure blank
Right bmp ->
pure (bitmapOfBMP bmp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment