问题描述
我可以创建一个新的图像对象并设置像素颜色,但生成的图像只是黑色而不是预期的灰色。对于位深度,我是否必须只包含一个包含 256 个元素的调色板,它会被保存为位深度 8?我应该打开保存的图像并检查调色板是否存在。
import jimp from 'jimp';
const newImage = new jimp(149,101);
for ( let x = 0; x < newImage.bitmap.width; x++ ) {
for ( let y = 0; y < newImage.bitmap.height; y++ ) {
newImage.setPixelColor(jimp.rgbaToInt(50,50,0),x,y);
}
}
// can see that the pixels have been set
console.log(newImage);
// attempting to set a custom color palette.
// this seems to not do anything. (is it ok to just have one element?)
newImage.bitmap.palette = [
{
red: 50,green: 50,blue: 50,quad: 0
}
]
// png (perhaps not an issue)
console.log(newImage.getExtension());
// writes the file but it's all black. Expected some shade of grey.
await newImage.writeAsync('new.bmp');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)