journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.68k stars 1.26k forks source link

Arabic language not supported in QR Code. #674

Open pramodkr123 opened 2 years ago

pramodkr123 commented 2 years ago

4.3.0

OPPO F19 PRO, Android 11

 public static String createQRCodeImage(String text) {
    BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
    Bitmap bitmap = null;

    String path = BKConstants.getDirectoryPath("");
    String fileName = "QRCode.jpg";
    File file = new File(path, fileName);
    if (file.exists()) file.delete();
    try {
        bitmap = barcodeEncoder.encodeBitmap(text, BarcodeFormat.QR_CODE, 200, 200);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return file.getAbsolutePath();
}
MeherBa commented 2 years ago

Did you get it working? i have the same issue

pramodkr123 commented 2 years ago

Try this code it's working

 public static String createQRCodeImage(Uri uri) {
    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
    hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");

    BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
    Bitmap bitmap = null;

    String path = BKConstants.getBKDirectoryPath("");
    String fileName = "QRCode.jpg";
    File file = new File(path, fileName);
    if (file.exists()) file.delete();
    try {
        BitMatrix bitMatrix = multiFormatWriter.encode(uri.toString(), BarcodeFormat.QR_CODE, 200, 200, hintMap);
        bitmap = barcodeEncoder.createBitmap(bitMatrix);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
        fileOutputStream.flush();
        fileOutputStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return file.getAbsolutePath();
}