Skip to content

Commit

Permalink
Support custom colors in BarcodeEncoder.java.
Browse files Browse the repository at this point in the history
  • Loading branch information
saifkhichi96 committed Feb 8, 2022
1 parent 2324a54 commit 8fdbbbe
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -19,21 +19,29 @@
* 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();
int[] pixels = new int[width * height];
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;
}
}

Expand Down

0 comments on commit 8fdbbbe

Please sign in to comment.