0

This is the function I am using to generate a QR file:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

public boolean generateQRCode(String qrCodeContent, String filePath, int width, int height) {
    try {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.encode(qrCodeContent, BarcodeFormat.QR_CODE, width, height);
        Path path = Paths.get(filePath);
        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
        return true;
    } catch (WriterException | IOException e) {
        log.error("Exception occurred while generating QR Code", e);
    }
    return false;
}

When I am sending the symbol in qrCodeContent string, nothing goes wrong, the QR code gets generated successfully.

However, when I scan the code, all those places where was there are replaced by ?.

The variable qrCodeContent is of type String which contains a normal string with literals like Your total saving are ₹ 100.00.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
samar taj Shaikh
  • 1,165
  • 11
  • 18
  • Never assume we know what API you're using. Unless only the standard JRE library is being used, always state what API you're using. It looks like whatever is 'doing OCR' is having character encoding problems or missing glyph problems somewhere in the chain. *Where* are you seeing that question mark? – g00se Mar 28 '23 at 12:22
  • as i said, after generating a QR code against a string. When i am scanning the QR code via my mobile-phone the QR code text generated after scanning has `?` in place of `₹` – samar taj Shaikh Mar 28 '23 at 12:30
  • Please also attach the calling code to your question, showing how that Rupee sign is being input – g00se Mar 28 '23 at 12:33
  • 1
    Adding `Map.of(EncodeHintType.CHARACTER_SET, "UTF-8")` as the last parameter to of the `encode()` method made it work for me. – Joachim Sauer Mar 28 '23 at 12:55
  • Yes. Strange that it doesn't default to UTF-8 – g00se Mar 28 '23 at 13:16
  • Also see [What are the supported values for CHARACTER_SET](https://groups.google.com/g/zxing/c/i8ABpVs9mjc) if you want to be certain that the specified value of `EncodeHintType.CHARACTER_SET` is valid at runtime. – skomisa Mar 29 '23 at 15:55

0 Answers0