I am trying to load a PNG using the JuicyPixels library and I am able to do this successfully but I then can't figure out what type the underlying image is. In the library the DynamicImage
is defined as follows.
data DynamicImage =
ImageY8 (Image Pixel8)
| ImageYA8 (Image PixelYA8)
| ImageRGB8 (Image PixelRGB8)
| ImageRGBA8 (Image PixelRGBA8)
| ImageYCbCr8 (Image PixelYCbCr8)
Through simple trial and error I was able to find out that it was a ImageRGBA8 by doing this.
img = (\(ImageRBA8 t) -> t) dynImage
then just doing
imageData img
In ghci to print the image data, all other types give an error. So how can I figure out the what type of DynamicImage
has been loaded without trial an error. I'm sure this is quite simple and I am just missing something.
DynamicImage
is just an ADT so you can pattern match against it in a function definition or case expression. The exact constructor used will depend on the type of image you loaded from the file (so in this case it was RGA8 but in other cases it could be different).
For example:
case img of
ImageY8 imgPixel8 -> ... do something ...
ImageYA8 imgPixelYA8 -> ...
ImageRGB8 imgPixelRGB8 -> ...
ImageRGBA8 imgPixelRGBA8 -> ...
ImageYCbCr8 imgPixelYCbCr8 -> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With