Skip to content

Commit 1762b84

Browse files
author
Aleksander Grinin
committed
Add articles to /java/developer-guide/barcode-generation section
1 parent e4995da commit 1762b84

13 files changed

Lines changed: 558 additions & 69 deletions

File tree

java/developer-guide/barcode-generation/set-barcode-checksum/_index.md renamed to java/developer-guide/barcode-generation/barcode-checksum/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Set Barcode Checksum"
33
description: "Enable optional checksums and understand symbologies with mandatory check digits."
44
type: docs
5-
weight: 40
5+
weight: 70
66
url: /java/developer-guide/barcode-generation/set-barcode-checksum/
77
---
88

java/developer-guide/barcode-generation/save-generated-barcodes/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Save Generated Barcodes"
33
description: "Save generated barcodes to raster and vector formats or write them to a stream."
44
type: docs
5-
weight: 30
5+
weight: 60
66
url: /java/developer-guide/barcode-generation/save-generated-barcodes/
77
---
88

java/developer-guide/barcode-generation/set-barcode-symbology-and-text/_index.md renamed to java/developer-guide/barcode-generation/symbology-and-text/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Barcode Symbology and Text"
33
description: "Learn how to select a barcode symbology and provide plain text, Unicode text, or raw binary data in Aspose.BarCode for Java."
44
type: docs
5-
weight: 10
5+
weight: 80
66
url: /java/developer-guide/barcode-generation/set-barcode-symbology-and-text/
77
---
88

java/developer-guide/barcode-generation/visual-parameters-and-layout/rotation-colors-borders-backgrounds/_index.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

java/developer-guide/barcode-generation/visual-parameters-and-layout/_index.md renamed to java/developer-guide/barcode-generation/visual-parameters/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Visual Parameters & Layout"
33
description: "Configure common barcode dimensions, padding, image bounds, text placement, and layout."
44
type: docs
5-
weight: 20
5+
weight: 90
66
url: /java/developer-guide/barcode-generation/visual-parameters-and-layout/
77
---
88

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "Customize Barcode Backgrounds"
3+
description: "Learn how to configure barcode background colors, transparency, padding, and contrast in Aspose.BarCode for Java."
4+
type: docs
5+
weight: 20
6+
url: /java/developer-guide/barcode-generation/visual-parameters/backgrounds/
7+
---
8+
9+
# Customize Barcode Backgrounds
10+
11+
Aspose.BarCode for Java allows you to configure the background of a generated barcode image, including solid colors, transparent backgrounds, and semi-transparent backgrounds.
12+
13+
Background settings do not change the encoded data, but they can affect recognition reliability.
14+
15+
The complete source code for the examples in this article is available on GitHub:
16+
17+
<a href="https://github.com/aspose-barcode/Aspose.BarCode-for-Java/blob/master/src/test/java/com/aspose/barcode/guide/generation/visual_parameters/ColorsExample.java" target="_blank">View ColorsExample.java</a>
18+
19+
<a href="https://github.com/aspose-barcode/Aspose.BarCode-for-Java/blob/master/src/test/java/com/aspose/barcode/guide/generation/visual_parameters/ImageAndLayoutParametersExample.java" target="_blank">View ImageAndLayoutParametersExample.java</a>
20+
21+
You can also browse the <a href="https://github.com/aspose-barcode/Aspose.BarCode-for-Java/tree/master/src/test/java/com/aspose/barcode/guide/generation" target="_blank">Generation examples directory</a>.
22+
23+
## Set a solid background color
24+
25+
Use `setBackColor` to configure the image background.
26+
27+
```java
28+
BarcodeGenerator generator = new BarcodeGenerator(
29+
EncodeTypes.QR,
30+
"BACKGROUND-EXAMPLE"
31+
);
32+
33+
generator.getParameters().setBackColor(
34+
new Color(245, 248, 252)
35+
);
36+
37+
generator.getParameters()
38+
.getBarcode()
39+
.setBarColor(new Color(20, 45, 90));
40+
41+
generator.save(
42+
"qr_custom_background.png",
43+
BarCodeImageFormat.PNG
44+
);
45+
```
46+
47+
## Use a dark background
48+
49+
```java
50+
BarcodeGenerator generator = new BarcodeGenerator(
51+
EncodeTypes.QR,
52+
"DARK-BACKGROUND"
53+
);
54+
55+
generator.getParameters().setBackColor(Color.BLACK);
56+
57+
generator.getParameters()
58+
.getBarcode()
59+
.setBarColor(Color.WHITE);
60+
61+
generator.save(
62+
"qr_dark_background.png",
63+
BarCodeImageFormat.PNG
64+
);
65+
```
66+
67+
Inverted barcodes can be less compatible with some readers. Use dark bars or modules on a light background when maximum interoperability is required.
68+
69+
## Create a transparent background
70+
71+
PNG supports an alpha channel. A fully transparent background can be created with an alpha value of `0`.
72+
73+
```java
74+
BarcodeGenerator generator = new BarcodeGenerator(
75+
EncodeTypes.QR,
76+
"TRANSPARENT-QR"
77+
);
78+
79+
generator.getParameters().setBackColor(
80+
new Color(255, 255, 255, 0)
81+
);
82+
83+
generator.save(
84+
"qr_transparent.png",
85+
BarCodeImageFormat.PNG
86+
);
87+
```
88+
89+
## Create a semi-transparent background
90+
91+
```java
92+
generator.getParameters().setBackColor(
93+
new Color(255, 255, 255, 128)
94+
);
95+
```
96+
97+
The alpha value ranges from `0` for fully transparent to `255` for fully opaque.
98+
99+
Not all image formats preserve transparency. JPEG does not support an alpha channel.
100+
101+
## Configure padding around the barcode
102+
103+
Padding adds blank space around the generated barcode image.
104+
105+
```java
106+
BarcodeGenerator generator = new BarcodeGenerator(
107+
EncodeTypes.CODE_128,
108+
"PADDING-EXAMPLE"
109+
);
110+
111+
generator.getParameters()
112+
.getBarcode()
113+
.getPadding()
114+
.getLeft()
115+
.setPixels(20);
116+
117+
generator.getParameters()
118+
.getBarcode()
119+
.getPadding()
120+
.getRight()
121+
.setPixels(20);
122+
123+
generator.getParameters()
124+
.getBarcode()
125+
.getPadding()
126+
.getTop()
127+
.setPixels(10);
128+
129+
generator.getParameters()
130+
.getBarcode()
131+
.getPadding()
132+
.getBottom()
133+
.setPixels(10);
134+
135+
generator.save(
136+
"code128_with_padding.png",
137+
BarCodeImageFormat.PNG
138+
);
139+
```
140+
141+
Padding is an image-layout setting. Left and right padding can reserve space for required quiet zones, but the required quiet-zone width depends on the symbology, X-dimension, and applicable barcode specification.
142+
143+
## Recommendations
144+
145+
- Maintain strong contrast between the barcode and its final background.
146+
- Test transparent images after placing them on the actual destination background.
147+
- Use an output format that preserves the required alpha channel.
148+
- Keep enough blank space around the symbol.
149+
- Do not treat arbitrary padding values as universal quiet-zone dimensions.
150+
- Validate the final image with the intended scanner and rendering pipeline.

java/developer-guide/barcode-generation/visual-parameters-and-layout/customize-barcode-size/_index.md renamed to java/developer-guide/barcode-generation/visual-parameters/barcode-size/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Customize Barcode Size"
33
description: "Configure X-dimension, bar height, auto-size modes, image bounds, and symbology-specific dimensions."
44
type: docs
5-
weight: 22
5+
weight: 10
66
url: /java/developer-guide/barcode-generation/visual-parameters-and-layout/customize-barcode-size/
77
---
88

0 commit comments

Comments
 (0)