2015-12-18 2 views
0

Я рисую контактные изображения на монохромном дисплее, но результаты плохие, но только порог применяется сглаживание (см. Сравнения здесь: dithering algorithms). Как я могу достичь заказанных или других (лучше) результатов сглаживания?Dither фото для монохромного дисплея (Android)

Вот код, я использую:

// 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)); 

Я попытался установить различные конфигурации растровой, но ничего не меняется.

ответ

0

Хорошо, вот ответ, который работал для меня: 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)); 
    } 
    } 
Смежные вопросы