Created
December 6, 2017 22:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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