JIMP(nodeJS)是否从上到下创建 bmp 文件?有没有办法扭转这种情况?

Does JIMP (nodeJS) create bmp files from top-to-bottom? Is there a way to reverse this?

我正在尝试在 nodeJS 中生成 bmp 图像(图形)以在 C 中使用以在低分辨率显示器上显示。

创建图形(使用 d3.js)并将 svg 代码转换为 bmp 工作正常(通过 svg2img 和 Jimp)并且 bmp 文件中的所有内容都正确显示。

当我尝试在低分辨率屏幕上显示它时,C 代码报告图像高度为负而失败。现在我读到 bmp 可以从上到下或从下到上存储 (here for example)。

Jimp 的工作方向是什么,如何反转?

我再次转换了我用 Jimp 生成的 bmp(使用 XnConvert)并尝试了生成的 bmp,它在低分辨率屏幕上成功显示。

在节点中:

        svg2img(body.select('.container').html(), function(error, buffer) {
            //returns a Buffer
            fs.writeFile('foo1.png', buffer, function(){
              Jimp.read('./foo1.png')
                .then(image => {
                  // Do stuff with the image.
                  image.background(0xffffffff).resize(1200, 500);
                  image.dither565();
                  image.write("./public/test.bmp"); // save
                })
                .catch(err => {
                  // Handle an exception.
                  res.send("error1");
                });
            });
        });

在 C 脚本日志中:

BMP_cfSize:1800054 
BMP_cfoffBits:54 
BMP_ciSize:40 
BMP_ciWidth:1200 
BMP_ciHeight:-500 <---------------------
//etc.
*****************************************

total_length:1800000,1800000
bytesPerLine = 3600
imageSize = -1800000

有没有办法在 Jimp 中恢复订单?还是我错过了其他东西? 或者尝试恢复 C 库中的顺序会更容易吗(我对 C 不是很好)?

正如评论中所指出的,在 Jimp 使用的 bmp-js 库中将负值设为正值 in this line 翻转了图像,但也解决了需要该顺序的 C 库的问题。

在 Jimp 中使用 image.flip(false, true),我可以在最终结果中保持正确的方向。

bmp-js GitHub 中报告的问题。