Skip to content

Commit 8fdbbbe

Browse files
authored
Support custom colors in BarcodeEncoder.java.
1 parent 2324a54 commit 8fdbbbe

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeEncoder.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,29 @@
1919
* Licensed under the Apache License, Version 2.0.
2020
*/
2121
public class BarcodeEncoder {
22-
private static final int WHITE = 0xFFFFFFFF;
23-
private static final int BLACK = 0xFF000000;
22+
private int bgColor = 0xFFFFFFFF;
23+
private int fgColor = 0xFF000000;
2424

2525

2626
public BarcodeEncoder() {
2727
}
2828

29+
public void setBackgroundColor(int bgColor) {
30+
this.bgColor = bgColor;
31+
}
32+
33+
public void setForegroundColor(int fgColor) {
34+
this.fgColor = fgColor;
35+
}
36+
2937
public Bitmap createBitmap(BitMatrix matrix) {
3038
int width = matrix.getWidth();
3139
int height = matrix.getHeight();
3240
int[] pixels = new int[width * height];
3341
for (int y = 0; y < height; y++) {
3442
int offset = y * width;
3543
for (int x = 0; x < width; x++) {
36-
pixels[offset + x] = matrix.get(x, y) ? BLACK : WHITE;
44+
pixels[offset + x] = matrix.get(x, y) ? fgColor : bgColor;
3745
}
3846
}
3947

0 commit comments

Comments
 (0)