# Barcode (/libs/barcode)



The LVGL Barcode utility enables you to generate Code-128 bar codes.  It uses the
[code128](https://github.com/fhunleth/code128) library by
[fhunleth](https://github.com/fhunleth).

Usage [#usage]

Set <ApiLink name="LV_USE_BARCODE" /> to `1` in `lv_conf.h`.

Use <ApiLink name="lv_barcode_create" /> to create a barcode object, and use
<ApiLink name="lv_barcode_update" /> to generate a barcode.

Call <ApiLink name="lv_barcode_set_scale" /> to adjust scaling,
call <ApiLink name="lv_barcode_set_dark_color" /> and <ApiLink name="lv_barcode_set_light_color" />
adjust colors.  Call <ApiLink name="lv_barcode_set_direction" /> to set the bar code's
orientation.

By default, <ApiLink name="LV_BARCODE_ENCODING_CODE128_GS1" /> encoding is used
and strips `[FCN1]` and spaces. Optionally use
<ApiLink name="lv_barcode_set_encoding" /> to set
<ApiLink name="LV_BARCODE_ENCODING_CODE128_RAW" />.

After any of a bar code's settings have changed, call
<ApiLink name="lv_barcode_update" /> again to regenerate it.

Notes [#notes]

* It is best not to manually set the width of the barcode, because when
  the width of the Widget is lower than the width of the barcode, the
  display will be incomplete due to truncation.
* The scale adjustment can only be an integer multiple, for example,
  <ApiLink name="lv_barcode_set_scale" display="lv_barcode_set_scale(barcode, 2)" /> means 2x scaling.
* The direction setting can be <ApiLink name="LV_DIR_HOR" /> or <ApiLink name="LV_DIR_VER" />.

Example [#example]

Create a Barcode [#create-a-barcode]

<LvglExample name="lv_example_barcode_1" path="libs/barcode/lv_example_barcode_1" />

API [#api]
