Set Barcode Colorscheme

This documentation provides a comprehensive guide on how to set the colorscheme for barcodes using the Aspose.BarCode Cloud SDK for Dart. The API allows customization of barcode appearance, including foreground and background colors, ensuring your barcodes match your design needs.

Overview

The GenerateApi interface includes methods to generate barcodes using different request formats:

  • generate: GET request with parameters in route and query string.
  • generateBody: POST request with parameters in the body (JSON or XML).
  • generateMultipart: POST request with parameters in multipart form.

Colorscheme Parameters

The foregroundColor and backgroundColor properties enable you to define the colors for the barcode:

  • foregroundColor: Specifies the color of the bars and text.
  • backgroundColor: Specifies the background color of the barcode image.

Both properties accept standard color names or ARGB values (e.g., AliceBlue or #FF000000).

Examples

Example 1: Setting Colors Using GET Request

import 'dart:io';
import 'dart:typed_data';
import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final fileName = "${Directory.current.path}${Platform.pathSeparator}qr.png";

  final Uint8List response = await generateApi.generate(
    EncodeBarcodeType.QR,
    "https://products.aspose.cloud/barcode/family/",
    foregroundColor: "DarkBlue",
    backgroundColor: "LightGray",
    imageFormat: BarcodeImageFormat.Png,
  );

  await File(fileName).writeAsBytes(response);

  print("File '$fileName' generated.");
}

Result Image is: Result image

Example 2: Setting Colors Using POST Request with JSON Body

import 'dart:io';
import 'dart:typed_data';

import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final file = File(
    "${Directory.current.path}${Platform.pathSeparator}Pdf417.png",
  );

  final imageParams = BarcodeImageParams();
  imageParams.foregroundColor = "#FF5733";
  imageParams.backgroundColor = "#FFFFFF";
  imageParams.imageFormat = BarcodeImageFormat.Jpeg;

  final generateParams = GenerateParams(
    EncodeBarcodeType.Pdf417,
    EncodeData("Aspose.BarCode.Cloud", EncodeDataType.StringData),
    imageParams,
  );

  final Uint8List response = await generateApi.generateBody(generateParams);

  file.writeAsBytes(response);

  print("File '${file.path}' generated.");
}

Result Image is: Result image

Example 3: Setting Colors Using Multipart Form POST

import 'dart:io';
import 'dart:typed_data';

import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';

Configuration makeConfiguration() {
  final envToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
  if (envToken != null) {
    return Configuration(accessToken: envToken);
  } else {
    return Configuration(
      clientId: "Client Id from https://dashboard.aspose.cloud/applications",
      clientSecret:
          "Client Secret from https://dashboard.aspose.cloud/applications",
    );
  }
}

Future<void> main() async {
  final configuration = makeConfiguration();
  final apiClient = ApiClient(configuration);
  final generateApi = GenerateApi(apiClient);

  final fileName =
      '${Directory.current.path}${Platform.pathSeparator}Code39.png';

  final Uint8List response = await generateApi.generateMultipart(
      EncodeBarcodeType.Code39, "Aspose",
      foregroundColor: "Green",
      backgroundColor: "Yellow",
      imageFormat: BarcodeImageFormat.Gif);

  await File(fileName).writeAsBytes(response);

  print("File '$fileName' generated.");
}

Result Image is: Result image

Conclusion

With GenerateApi in Aspose.BarCode Cloud SDK for Dart, 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.