Mirokov
|
Problems encoding UTF8 in Aztec Code (non-latin characters)
We are trying to encode UTF8 in the Aztec Barcode Type with the .NET Barcode Generator. We have this function:
[Function(IsVisible = true, Category = "ProLogis", Namespace = "BarcodeFunctions", Description = "GetAztec")]
public static string GetAztec(string data, int errorCorrectionLevel = 1, int numberOfSymbols = 1, decimal xDimensionCm = 0.03m)
{
try
{
if (string.IsNullOrEmpty(data)) return BitmapToBase64(new Bitmap(1, 1));
foreach (var chr in data)
if (chr > 255)
data = data.Replace(chr.ToString(), "~d" + (int)chr);
using AztecBarcode aztecCode = new AztecBarcode();
aztecCode.ErrorCorrectionLevel = errorCorrectionLevel;
aztecCode.NumberOfSymbols = numberOfSymbols;
aztecCode.DataToEncode = data;
aztecCode.ApplyTilde = true;
aztecCode.XDimensionCM = (float)xDimensionCm;
aztecCode.Resolution = IDAutomation.Windows.Forms.AztecBarcode.Resolutions.Custom;
aztecCode.ResolutionCustomDPI = 400;
return BitmapToBase64(aztecCode.BMPPicture);
}
catch (Exception e)
{
string message = $"Error creating Aztec as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}
We tried to build the same as here (previous version of the software):
[Function(IsVisible = true, Category = "ProLogis", Namespace = "BarcodeFunctions", Description = "GetAztec")]
public static string GetAztec(string data, int errorCorrectionLevel = 1, int numberOfSymbols = 1, decimal xDimensionCm = 0.03m)
{
try
{
if (string.IsNullOrEmpty(data)) return BitmapToBase64(new Bitmap(1, 1));
foreach (var chr in data)
if (chr > 255)
data = data.Replace(chr.ToString(), "~d" + (int)chr);
using AztecBarcode aztecCode = new AztecBarcode();
aztecCode.ErrorCorrectionLevel = errorCorrectionLevel;
aztecCode.NumberOfSymbols = numberOfSymbols;
aztecCode.DataToEncode = data;
aztecCode.ApplyTilde = true;
aztecCode.XDimensionCM = (float)xDimensionCm;
aztecCode.Resolution = IDAutomation.Windows.Forms.AztecBarcode.Resolutions.Custom;
aztecCode.ResolutionCustomDPI = 400;
return BitmapToBase64(aztecCode.BMPPicture);
}
catch (Exception e)
{
string message = $"Error creating Aztec as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}
Here is our test:
[DataRow("NonLatinCharacters", "日本語テスト Español Français", 10, 1, 0.03)]
public void Aztec(string testName, string testData, int errorCorectionLevel, int numberOfSymbols,
double xDimensionCm)
{
// Error Correction Levels: Aztec supports levels 1 (low) to 23 (max). Higher levels increase redundancy but reduce data capacity.
// numberOfSymbols: Typically 1 for most use cases. Use >1 for large datasets split across linked Aztec symbols.
// xDimensionCm: Must be ≥ 0.01 cm (practical minimum for scanners). Larger values improve readability but increase symbol size.
var decimalxDimensionCm = (decimal)xDimensionCm;
// todo: use apply tilde or not?? quietzone: TE thinks 0, but maybe 1 or 2? Testdata ok?
testName = $"{nameof(Aztec)}_{testName}_";
var originalData = BarcodeFunctions.GetAztec(testData, errorCorectionLevel, numberOfSymbols, decimalxDimensionCm);
File.WriteAllBytes($"{testName}Test.png", Convert.FromBase64String(originalData));
var data = NET.BarcodeFunctions.GetAztec(testData, errorCorectionLevel, numberOfSymbols, decimalxDimensionCm);
File.WriteAllBytes($"{testName}Test_NET.png", Convert.FromBase64String(data));
Assert.AreEqual(originalData, data);
}
Previous version output: ÿ85ÿ12ÿ86|86|73|88 Español Français
Newer version output: ÿ85ÿ12ÿ86|86|73|88 Español Français
We would like to have at least the old functionality: that the Español Français is displayed correctly.
Can you tell us what we need to change to achieve this?
04-17-25 18 day(s) ago
 Report Abuse
|