It will be great if someone can clarify how to use dpi while encoding/generating barcodes. I am using the API first time, so greatly appreciate your answers.
I am trying to generate Data Matrix barcodes to be of size 0.24in @ 300dpi. That is 72px(=0.24*300) in width and height.
However, the generated barcode is not 0.24in but much larger.
I get the required size when the dimensions are 18px.
Am I missing something here?
Or, should I have to scale the generated barcode later on?
In general, I am interested in knowing how should I account for printing barcodes on printers with different resolutions(dpi)?
Please see the below sample code.
int dpi = 300;
int size = 0.24; //inches
int widthInPixels = size * dpi; // 72px
int heightInPixels = widthInPixels; //square barcode
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.MIN_SIZE, new Dimension(widthInPixels, heightInPixels));
// write out
String contents = ... //valid content
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode(contents, BarcodeFormat.DATA_MATRIX, widthInPixels, heightInPixels, hints);
Path path = ... //some path
MatrixToImageWriter.writeToPath(result, "PNG", path);