From 8fdbbbef5e27fcd7162198ecca543fc7bd6b2111 Mon Sep 17 00:00:00 2001 From: Muhammad Saif Ullah Khan Date: Tue, 8 Feb 2022 18:17:58 +0100 Subject: [PATCH] Support custom colors in BarcodeEncoder.java. --- .../journeyapps/barcodescanner/BarcodeEncoder.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeEncoder.java b/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeEncoder.java index ed1729ec5..502b9cc93 100644 --- a/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeEncoder.java +++ b/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeEncoder.java @@ -19,13 +19,21 @@ * Licensed under the Apache License, Version 2.0. */ public class BarcodeEncoder { - private static final int WHITE = 0xFFFFFFFF; - private static final int BLACK = 0xFF000000; + private int bgColor = 0xFFFFFFFF; + private int fgColor = 0xFF000000; public BarcodeEncoder() { } + public void setBackgroundColor(int bgColor) { + this.bgColor = bgColor; + } + + public void setForegroundColor(int fgColor) { + this.fgColor = fgColor; + } + public Bitmap createBitmap(BitMatrix matrix) { int width = matrix.getWidth(); int height = matrix.getHeight(); @@ -33,7 +41,7 @@ public Bitmap createBitmap(BitMatrix matrix) { for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { - pixels[offset + x] = matrix.get(x, y) ? BLACK : WHITE; + pixels[offset + x] = matrix.get(x, y) ? fgColor : bgColor; } }