encode method

  1. @override
BitMatrix encode(
  1. String contents,
  2. BarcodeFormat format,
  3. int width,
  4. int height, [
  5. Map<EncodeHintType, Object>? hints,
])
override

@param contents The contents to encode in the barcode @param format The barcode format to generate @param width The preferred width in pixels @param height The preferred height in pixels @param hints Additional parameters to supply to the encoder @return BitMatrix representing encoded barcode image @throws WriterException if contents cannot be encoded legally in a format

Implementation

@override
BitMatrix encode(
  String contents,
  BarcodeFormat format,
  int width,
  int height, [
  Map<EncodeHintType, Object>? hints,
]) {
  Encoding? charset; // Do not add any ECI code by default
  int eccPercent = Encoder.DEFAULT_EC_PERCENT;
  int layers = Encoder.DEFAULT_AZTEC_LAYERS;
  if (hints != null) {
    if (hints.containsKey(EncodeHintType.CHARACTER_SET)) {
      charset = CharacterSetECI.getCharacterSetECIByName(
        hints[EncodeHintType.CHARACTER_SET] as String,
      )?.charset;
    }
    if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
      eccPercent =
          int.parse(hints[EncodeHintType.ERROR_CORRECTION].toString());
    }
    if (hints.containsKey(EncodeHintType.AZTEC_LAYERS)) {
      layers = int.parse(hints[EncodeHintType.AZTEC_LAYERS].toString());
    }
  }
  return _encodeStatic(
    contents,
    format,
    width,
    height,
    charset,
    eccPercent,
    layers,
  );
}