Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: QR Code qzestion

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default QR Code qzestion

    hello
    ¸im writing program for read and write QR code in netBeans 8.2 . I use library zxing core-3.3.0.jar and zxing javase-3.3.0.jar
    how I make that write Č,Š Ž (ISO-8859-2) charset in QR Code

    // My imports:
    import javax.imageio.ImageIO;
    import com.google.zxing.BarcodeFormat;
    import com.google.zxing.EncodeHintType;
    import com.google.zxing.MultiFormatWriter;
    import com.google.zxing.WriterException;
    import com.google.zxing.client.j2se.MatrixToImageWriter;
    import com.google.zxing.common.BitMatrix;
    import com.google.zxing.qrcode.QRCodeWriter;
    import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
    import java.util.HashMap;
    import java.util.Map;
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    import com.google.zxing.EncodeHintType;
    import com.google.zxing.BarcodeFormat;
    import com.google.zxing.BinaryBitmap;
    import com.google.zxing.LuminanceSource;
    import com.google.zxing.MultiFormatReader;
    import com.google.zxing.MultiFormatWriter;
    import com.google.zxing.NotFoundException;
    import com.google.zxing.Result;
    import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
    import com.google.zxing.client.j2se.MatrixToImageWriter;
    import com.google.zxing.common.BitMatrix;
    import com.google.zxing.common.HybridBinarizer;
    import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
    import com.google.zxing.EncodeHintType;
    import java.nio.file.FileSystems;
    import java.nio.file.Path;
     
    //my code for writing QR code;
    public void pisi(){
             try{
                String qrCodeData = "česnja na trorti" ;
                String filePath = beseda2;
               String charset = "ISO-8859-2"; // or "ISO-8859-1"
                Map < EncodeHintType, ErrorCorrectionLevel > hintMap = new HashMap < EncodeHintType, ErrorCorrectionLevel > ();
                hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
                BitMatrix matrix = new MultiFormatWriter().encode(
                    new String(qrCodeData.getBytes(charset), charset),
                    BarcodeFormat.QR_CODE, 400, 400, hintMap);
                MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
                    .lastIndexOf('.') + 1), new File(filePath));
                //System.out.println("QR koda je ustvarjena!");
            } catch (Exception e) {
               // System.err.println(e);
            }
         }

  2. #2
    Junior Member
    Join Date
    Dec 2017
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: QR Code qzestion

    Hello
    I find answer for my problem here
    https://stackoverflow.com/questions/...ng-using-zxing

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: QR Code qzestion

    Hi, below is an alternative solution based on Free Spire.Barcode for Java. Hope it helps.

    import com.spire.barcode.BarCodeGenerator;
    import com.spire.barcode.BarCodeType;
    import com.spire.barcode.BarcodeSettings;
    import com.spire.barcode.QRCodeECL;
     
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
     
    public class QRCode {
     
        public static void main(String[] args) throws IOException {
     
            //create an instance of BarcodeSettings
            BarcodeSettings settings = new BarcodeSettings();
            //set barcode type
            settings.setType(BarCodeType.QR_CODE);
            //set barcode data
            settings.setData("Č,Š Ž (ISO-8859-2)");
            //set dispaly text
            settings.setData2D("Č,Š Ž (ISO-8859-2)");
            //show text on bottom
            settings.setShowTextOnBottom(true);
            //set the border invisible
            settings.hasBorder(false);
            //set width of the barcode module
            settings.setX(2);
            //set the error correction level
            settings.setQRCodeECL(QRCodeECL.M);
            //create BarCodeGenerator object based on settings
            BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
            //generate image data and store in BufferedImage instance
            BufferedImage bufferedImage = barCodeGenerator.generateImage();
            //save to image
            ImageIO.write(bufferedImage,"png",new File("QR_CODE.png"));
            System.out.println("Complete!");
        }
    }

Similar Threads

  1. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  2. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  3. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM