File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
zxing-android-embedded/src/com/journeyapps/barcodescanner Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -172,11 +172,13 @@ try {
172172} catch (Exception e) {
173173
174174}
175+ ```
175176
176- No customization of the image is currently supported, including changing colors or padding. If you
177- require more customization, copy and modify the source for the encoder.
177+ To customize the generated barcode image, use the ` setBackgroundColor ` and ` setForegroundColor ` functions of the
178+ ` BarcodeEncoder ` class with a [ ` @ColorInt ` ] ( https://developer.android.com/reference/androidx/annotation/ColorInt )
179+ value to update the background and foreground colors of the barcode respectively. By default, the barcode has a
180+ white background and black foreground.
178181
179- ```
180182
181183### Changing the orientation
182184
Original file line number Diff line number Diff line change 1919 * Licensed under the Apache License, Version 2.0.
2020 */
2121public 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
You can’t perform that action at this time.
0 commit comments