Floyd-Steinberg抖动算法简直量身为价签这种低颜色呈现设备准备的。由于价签的墨水屏能够呈现的色彩非常有限,根据型号不同,有的只能显示黑白,有的只能显示黑白红,有的只能显示黑白黄,所以对于一张普通图片,需要将其转换为两色或者三色才能比较好地在价签上展示出来。
核心代码如下:
public class BMPConverter {
public static RGBTriple[] getPalette(int deviceType) {
final RGBTriple[] palette;
if (deviceType == 0) {
//黑白价签
palette = new RGBTriple[]{
new RGBTriple(0, 0, 0),
new RGBTriple(255, 255, 255)
};
} else if (deviceType == 1) {
//黑白红价签
palette = new RGBTriple[]{