New User? Sign Up  |  Sign In  |  Help
Barcode support and
tutorials from IDAutomation
and the community.
Click for the BBB Business Review of this Computers Hardware, Software & Services in Tampa FL
Resolved Questions

Problems encoding Data Matrix (non-latin characters) in .NET


Hello, we tried porting the DataMatrix from the old version of the software with the .NET Barcode Generator. We are having an issue encoding non-latin characters and size; we have this function:

public static string GetDataMatrix(string data)
{
try
{
if (string.IsNullOrEmpty(data)) return BitmapToBase64(new Bitmap(1, 1));
using DataMatrixBarcode dataMatrix = new DataMatrixBarcode();
dataMatrix.DataToEncode = data;
dataMatrix.EncodingMode = IDAutomation.Windows.Forms.DataMatrixBarcode.EncodingModes.Ascii;
dataMatrix.Resolution = IDAutomation.Windows.Forms.DataMatrixBarcode.Resolutions.Custom;
dataMatrix.ResolutionCustomDPI = 400;
return BitmapToBase64(dataMatrix.BMPPicture);
}
catch (Exception e)
{
string message = $"Error creating DataMatrix as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}

into new version (.NET Generator):
public static string GetDataMatrix(string data)
{
var compatibilityFactor = 1.88m; // empirical value
var applyTilde = false;
try
{
if (string.IsNullOrEmpty(data))
{
using var newBitmap = new Bitmap(1, 1);
return BitmapToBase64(newBitmap);
}

var moduleSize = (int)Math.Round((0.03m * 400m) * compatibilityFactor / 2.54m); // 400 DPI conversion
var obj = new DataMatrix();
var bmpstream = obj.EncodeDM(data, applyTilde, IDAutomatization.DataMatrix.EncodingModes.Ascii, -1, 3,
moduleSize);
using var mStream = new MemoryStream(bmpstream);
using var bitmap = (Bitmap)Image.FromStream(mStream);
return BitmapToBase64(bitmap);
}
catch (Exception e)
{
var message = $"Error creating DataMatrix as Image for value {data} Exception: {e.Message}";
throw new Exception(message);
}
}

Here are our tests:
[DataRow("SpecialChars", "https://test.com/?id=123&secret=~!@")]
[DataRow("Non Latin", "Español Français")]
public void DataMatrix(string testName, string testData)
{
testName = $"{nameof(DataMatrix)}_{testName}_";
var originalData = BarcodeFunctions.GetDataMatrix(testData);
File.WriteAllBytes($"{testName}_old.png", Convert.FromBase64String(originalData));
var data = NET.BarcodeFunctions.GetDataMatrix(testData);
File.WriteAllBytes($"{testName}_new.png", Convert.FromBase64String(data));
Assert.AreEqual(originalData, data);
}

Could you provide us with some guidance on the parameters:
Format
ApplyTilde
QuietZone
Module Size
Do you think we have done right in converting those from the old solution, or do you have some things we could improve? We are trying to achieve the same barcode (size) as we had before.
Also some additional explanation on the Format parameter would be welcome. What are its possible values, what effect do they have?


04-17-25     18 day(s) ago    

  Report Abuse

 

Brant

Best Answer

To encode non-latin characters in Data Matrix, set the encoding mode to Auto or Byte. The size of the Data Matrix symbol is a combination of Format and Module Size. Different sizes are also achieved from the various generation methods, such as BMP or the use of the font. I recommend you refer to the Visual Studio example in the download folder at "Data Matrix - BarcodeGenerationExample C#.NET - bin - Release - signed - BarcodeGenerationExample.exe" to find the best size. The parameters are explained at the bottom of the .NET Data Matrix Code Examples.

Posted 18 day(s) ago

(0)
(0)
  Report Abuse
 
Find Interesting
 
Email to Others
 
Bookmark
 
Subscribe to Answer Alert
No comments yet.     Be the first to comment.

Email this question link to friends
You must enter an email address, if name is entered or vice-versa for each friend.
Friend #1 -
Friend #2 -
Friend #3 -
Friend #4 -
Friend #5 -
  Your comment on this question
  |         |  
bold  italic  underline  strike       big  small       superscript  subscript 
  Allows to add a link. Added links would only be converted to actual clickable link, when the domain of the link is white-listed by administrator.
Caption :
Link URL :
(Must starts with "http://")
Add  |   Cancel
  Allow to insert an image. Must be among the following file types - *.jpg, *.gif, *.png & *.bmp.
Image Url :   Upload New
(Image url must always starts with " http:// ")
Width : pixels
(Must not be greater than 450px. Enter 0px for no resize)
Add  |   Cancel
  Allow to insert YouTube video. Insert the video embed code.
Embed Code :
Add  |   Cancel
Up to 5000 Characters are allowed. Current Count: 0
  Your comment on this answer
  |         |  
bold  italic  underline  strike       big  small       superscript  subscript 
  Allow you to add a link. Added links would only be converted to actual clickable link, when the domain of the link is white-listed by administrator.
Caption :
Link URL :
(Must start with "http://" or "https://")
Add  |   Cancel
  Allow to insert an image. Must be among the following file types - *.jpg, *.gif, *.png & *.bmp.
Image Url :   Upload New
(Image url must always start with "http://" or "https://")
Width : pixels
(Must not be greater than 450px. Enter 0px for no resize)
Add  |   Cancel
  Allow to insert YouTube video. Insert the video embed code.
Embed Code :
Add  |   Cancel
Up to 5000 characters are allowed. Current Count: 0

You may answer and comment on any thread according to the Terms and Conditions.

 © Copyright 2021 IDAutomation.com, Inc., All Rights Reserved. Legal Notices.

 Barcode Fonts | Components | Scanners | Support | Contact Us
Training Videos on YouTube Join us on Google Plus Join us on LinkedIn Follow us on Twitter Like us on Facebook