gpt4 book ai didi

image - 使用 node.js 从图像文件中获取像素数组

转载 作者:搜寻专家 更新时间:2023-10-31 23:02:40 25 4
gpt4 key购买 nike

是否可以使用 node.js 从本地镜像文件中获取 RGB 值数组?我正在尝试编写一个脚本,该脚本将文件路径作为其参数并返回一个表示像素数据的数组。

function getPixelArray(filePath){
//return an array of RGB values that correspond to the image
}

最佳答案

你可以试试https://www.npmjs.com/package/jimp这可能有用:

Jimp.read("http://www.example.com/path/to/lenna.jpg", function (err, image) {
image.getPixelColor(x, y); // returns the colour of that pixel e.g. 0xFFFFFFFF
});

要获得 RGB,您可以使用:

Jimp.intToRGBA(hex); // e.g. converts 0xFFFFFFFF to {r: 255, g: 255, b: 255, a:255} 

关于image - 使用 node.js 从图像文件中获取像素数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12286039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com