Skip to content

Instantly share code, notes, and snippets.

@h-hirai
Created April 3, 2012 17:48
Show Gist options
  • Save h-hirai/2294086 to your computer and use it in GitHub Desktop.
Save h-hirai/2294086 to your computer and use it in GitHub Desktop.
tried to use Codec.BMP
import Codec.BMP
import Data.Word (Word8)
import Data.ByteString (pack)
pixcelToFlatByteString height width px = pack $ rep height $ rep width px
where rep n = concat . replicate n
pixcelToPackedRGBA height width px =
packRGBA32ToBMP width height $ pixcelToFlatByteString height width px
main = do
let
width = 128
height = 32
red = pixcelToPackedRGBA height width [255,0,0,0]
green = pixcelToPackedRGBA height width [0,255,0,0]
blue = pixcelToPackedRGBA height width [0,0,255,0]
black = pixcelToPackedRGBA height width [0,0,0,255]
writeBMP "trial.red.bmp" red
writeBMP "trial.green.bmp" green
writeBMP "trial.blue.bmp" blue
writeBMP "trial.black.bmp" black
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment