jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
14.05k stars 760 forks source link

Printing BMP file using jimp + ffi #450

Closed stathopou closed 6 years ago

stathopou commented 6 years ago

Hello,

In my electron application, I load a .bmp file using Jimp, which I want to send to a receipt thermal printer. The communication with the printer is made using NodeFFI, where I load the necessary dll file. The printing function requires a pointer to the bits of the bitmap file to be printed.

Using Jimp, getBuffer should get me the desired pointer to the BMP file. However, I need to omit the header of the BMP file, and go straight to the actual bits. Can this be accomplished using getBuffer? I have made many different approaches but none seems to be working.

In this project I am using jimp, ref and ffi modules, and also I have defined the necessary BITMAP struct type (https://msdn.microsoft.com/en-us/library/windows/desktop/dd183371(v=vs.85).aspx).

hipstersmoothie commented 6 years ago

Jimp returns an encoded bmp. You could just parse the header in js to get to the start of the data. I don’t think that bmp-js has the ability to partially encode an image.

Could you use the raw bitmap before it’s encoded to a filetype? You could access this through image.bitmap I think.