Deno convert bmp image file data into a Uint8Array

163 views Asked by At

I am currently trying to load a .bmp image file with Deno and then convert the data of the image into a black/white Uint8Array.

I load the image using:

const imageFile = await Deno.readFile('./path/to/my/image.bmp');

This returns me a Uint8Array, but this is not only the image itself, it contains also other data, like the image header or other metadata.

I will try to explain what I would like to do with an example. I have the following bitmap image file. Each field represents one pixel:

enter image description here 4x4 bitmap

This bitmap would then output the following Uint8Array to me:

// hex
[ 0x5A, 0x5A ]

// binary
[ 0b01011010, 0b01011010 ]

// visual
[
  0101
  1010,
  0101
  1010
]

Is it possible to achieve this using Deno? Any suggestion is appreciated! Thanks!

~Mqx

0

There are 0 answers