【问题标题】:Dither a photo for monochrome display (Android)为单色显示抖动照片 (Android)
【发布时间】:2015-12-18 21:59:32
【问题描述】:

我在单色显示器上绘制联系人图片,但结果很差,显然只应用了阈值抖动(请参阅此处的比较:dithering algorithms)。我怎样才能获得 有序 或其他(更好的)抖动结果?

这是我使用的代码:

// RGB_565 is most suitable for monochrome display
Bitmap b = Bitmap.createBitmap(desW, desH, Bitmap.Config.RGB_565);
// Set the density to default to avoid scaling.
b.setDensity(DisplayMetrics.DENSITY_DEFAULT);
Canvas c = new Canvas(b);
c.drawBitmap(photo, source, destination, new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG));

我尝试设置不同的位图配置,但没有任何改变。

【问题讨论】:

    标签: android


    【解决方案1】:

    好的,这是对我有用的答案:How to convert a 24 Bit PNG to 3 Bit PNG using Floyd–Steinberg dithering?

    我只是将BufferedImage 替换为Bitmap,将方法getRGB(x, y) 的调用替换为getPixel(x,y),并将助手类实现替换为:

      static class C3 {
        int r, g, b;
    
        public C3(int c) {
          this.r = Color.red(r);
          this.g = Color.green(c);
          this.b = Color.blue(c);
        }
        public C3(int r, int g, int b) {
          this.r = r;
          this.g = g;
          this.b = b;
        }
    
        public C3 add(C3 o) {
          return new C3(r + o.r, g + o.g, b + o.b);
        }
        public C3 sub(C3 o) {
          return new C3(r - o.r, g - o.g, b - o.b);
        }
        public C3 mul(double d) {
          return new C3((int) (d * r), (int) (d * g), (int) (d * b));
        }
        public int diff(C3 o) {
          return Math.abs(r - o.r) +  Math.abs(g - o.g) +  Math.abs(b - o.b);
        }
    
        public int toRGB() {
          return Color.rgb(clamp(r), clamp(g), clamp(b));
        }
        public int clamp(int c) {
          return Math.max(0, Math.min(255, c));
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      相关资源
      最近更新 更多