Issue
I'm trying to encode a PDF417 and whenever I set the PDF417_COMPACTION
to Compaction.TEXT
I get this crash:
java.lang.ArrayIndexOutOfBoundsException: length=128; index=8226
at com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.isMixed(PDF417HighLevelEncoder.java:456)
at com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.encodeText(PDF417HighLevelEncoder.java:298)
at com.google.zxing.pdf417.encoder.PDF417HighLevelEncoder.encodeHighLevel(PDF417HighLevelEncoder.java:185)
at com.google.zxing.pdf417.encoder.PDF417.generateBarcodeLogic(PDF417.java:649)
at com.google.zxing.pdf417.PDF417Writer.bitMatrixFromEncoder(PDF417Writer.java:107)
at com.google.zxing.pdf417.PDF417Writer.encode(PDF417Writer.java:87)
at com.google.zxing.MultiFormatWriter.encode(MultiFormatWriter.java:102)
Here is the code for how I am trying to create the barcode:
var hints: MutableMap<EncodeHintType, Any>?
hints = EnumMap<EncodeHintType, Any>(EncodeHintType::class.java)
hints[EncodeHintType.CHARACTER_SET] = "UTF-8"
hints[EncodeHintType.ERROR_CORRECTION] = 6
hints[EncodeHintType.PDF417_COMPACTION] = Compaction.TEXT
val writer = MultiFormatWriter()
val result: BitMatrix
try {
result = writer.encode(contents, format, img_width, img_height, hints)
} catch (iae: WriterException) {
// Unsupported format
return null
}
Is this a bug or am i doing something wrong?
Solution
What is your img_width, img_height? This is my solution, you need to use realWidth = bitMatrix.getWidth()....:
BitMatrix bitMatrix = new MultiFormatWriter().encode(mContent, barcodeFormat, mWidth, mHeight, hintsMap);
int realWidth = bitMatrix.getWidth();
int realHeight = bitMatrix.getHeight();
int[] pixels = new int[realWidth * realHeight];
for (int i = 0; i < realHeight; i++) {
for (int j = 0; j < realWidth; j++) {
if (bitMatrix.get(j, i)) {
pixels[i * realWidth + j] = 0x00000000;
} else {
pixels[i * realWidth + j] = 0xffffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(pixels, 0, realWidth, realWidth, realHeight, Bitmap.Config.RGB_565);
Answered By - Aashutosh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.