Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation provides a comprehensive guide on how to set the colorscheme for barcodes using the Aspose.BarCode Cloud SDK for Java. The API allows customization of barcode appearance, including foreground and background colors, ensuring your barcodes match your design needs.
The GenerateApi
interface includes methods to generate barcodes using different request formats:
The foregroundColor
and backgroundColor
properties enable you to define the colors for the barcode:
Both properties accept standard color names or ARGB values (e.g., AliceBlue
or #FF000000
).
import com.aspose.barcode.cloud.ApiClient;
import com.aspose.barcode.cloud.api.GenerateApi;
import com.aspose.barcode.cloud.model.BarcodeImageFormat;
import com.aspose.barcode.cloud.model.EncodeBarcodeType;
import com.aspose.barcode.cloud.requests.GenerateRequestWrapper;
import java.io.File;
public class GenerateGet {
public static void main(String[] args) {
String accessToken = System.getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
ApiClient client;
if (accessToken != null && !accessToken.isEmpty()) {
client = new ApiClient(accessToken);
} else {
client =
new ApiClient(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications");
}
GenerateApi generateApi = new GenerateApi(client);
try {
GenerateRequestWrapper request =
new GenerateRequestWrapper(
EncodeBarcodeType.QR, "https://products.aspose.cloud/barcode/family/");
request.foregroundColor = "DarkBlue";
request.backgroundColor = "LightGray";
request.imageFormat = BarcodeImageFormat.PNG;
File barcodeImage = generateApi.generate(request);
System.out.println("Barcode image saved to file " + barcodeImage.getAbsolutePath());
} catch (Exception e) {
System.err.println("Error");
e.printStackTrace();
System.exit(1);
}
}
}
Result Image is:
import com.aspose.barcode.cloud.ApiClient;
import com.aspose.barcode.cloud.api.GenerateApi;
import com.aspose.barcode.cloud.model.BarcodeImageFormat;
import com.aspose.barcode.cloud.model.BarcodeImageParams;
import com.aspose.barcode.cloud.model.EncodeBarcodeType;
import com.aspose.barcode.cloud.model.EncodeData;
import com.aspose.barcode.cloud.model.EncodeDataType;
import com.aspose.barcode.cloud.model.GenerateParams;
import com.aspose.barcode.cloud.requests.GenerateBodyRequestWrapper;
import java.io.File;
public class GenerateBody {
public static void main(String[] args) {
String accessToken = System.getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
ApiClient client;
if (accessToken != null && !accessToken.isEmpty()) {
client = new ApiClient(accessToken);
} else {
client =
new ApiClient(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications");
}
GenerateApi generateApi = new GenerateApi(client);
try {
EncodeData encodeData = new EncodeData("Aspose.BarCode.Cloud");
encodeData.setDataType(EncodeDataType.STRING_DATA);
BarcodeImageParams imageParams = new BarcodeImageParams();
imageParams.setForegroundColor("#FF5733");
imageParams.setBackgroundColor("#FFFFFF");
imageParams.setImageFormat(BarcodeImageFormat.JPEG);
GenerateParams generateParams =
new GenerateParams(EncodeBarcodeType.PDF417, encodeData);
generateParams.setBarcodeImageParams(imageParams);
GenerateBodyRequestWrapper request = new GenerateBodyRequestWrapper(generateParams);
File barcodeImage = generateApi.generateBody(request);
System.out.println("Barcode image saved to file " + barcodeImage.getAbsolutePath());
} catch (Exception e) {
System.err.println("Error");
e.printStackTrace();
System.exit(1);
}
}
}
Result Image is:
import com.aspose.barcode.cloud.ApiClient;
import com.aspose.barcode.cloud.api.GenerateApi;
import com.aspose.barcode.cloud.model.BarcodeImageFormat;
import com.aspose.barcode.cloud.model.EncodeBarcodeType;
import com.aspose.barcode.cloud.requests.GenerateMultipartRequestWrapper;
import java.io.File;
public class GenerateMultipart {
public static void main(String[] args) {
String accessToken = System.getenv("TEST_CONFIGURATION_ACCESS_TOKEN");
ApiClient client;
if (accessToken != null && !accessToken.isEmpty()) {
client = new ApiClient(accessToken);
} else {
client =
new ApiClient(
"Client Id from https://dashboard.aspose.cloud/applications",
"Client Secret from https://dashboard.aspose.cloud/applications");
}
GenerateApi generateApi = new GenerateApi(client);
try {
GenerateMultipartRequestWrapper request =
new GenerateMultipartRequestWrapper(EncodeBarcodeType.CODE39, "Aspose");
request.foregroundColor = "Green";
request.backgroundColor = "Yellow";
request.imageFormat = BarcodeImageFormat.GIF;
File barcodeFile = generateApi.generateMultipart(request);
System.out.println("Barcode image saved to file " + barcodeFile.getAbsolutePath());
} catch (Exception e) {
System.err.println("Error");
e.printStackTrace();
System.exit(1);
}
}
}
Result Image is:
With GenerateApi
in Aspose.BarCode Cloud SDK for Java, you can easily generate barcodes with customized colors. Whether you prefer GET, POST with JSON, or multipart form POST, the flexibility of this API ensures seamless integration and customization of barcodes in your applications.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.