Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:10+00:00 2026-05-29T11:07:10+00:00

Im trying to use ZXing library to develop a Java project for decoding a

  • 0

Im trying to use ZXing library to develop a Java project for decoding a QR code. However, some of the image containing QR code can not be decoded by running my project, but these are working fine with Online ZXing decoder. I am just curious does the ZXing released version is the same as they are using for Online decoder? or they have tweaked the online version. I’m pulling my hair because of this confusion.

public class Validator implements IValidator {
    private static Logger logger = Logger.getLogger(Validator.class);
    private BufferedImage currentImage;
    private String resultText;
    private float moduleSize;
    private ResultPoint[] patternCenters;
    private int blockSizePower;

    public Validator(BufferedImage imageFile) {
        this.currentImage = imageFile;
        setLuminanceThreshold(3); //default value used by validator
    }

    public Validator(File imageFile) {
        // take input image file and store in a BufferedImage variable
        try {
            currentImage = ImageIO.read(imageFile);
        } catch (IOException e) {
            logger.error("Image cannot be opened. There is no such image file. ", e);
        }
    }


    /**
     * <p>Validating the QR code</p>
     *
     * @return true if the QR code can be decoded
     */
    @Override
    public boolean validateQRCode() {
        return validateQRCode(null);
    }

    public boolean validateQRCode(Hashtable outValues) {
        return validateQRCode(outValues, true);
    }

    // if localLuminanceCheck == true then call HybridBinarizer, otherwise call GlobalHistogramBinarizer  
    public boolean validateQRCode(Hashtable outValues, boolean localLuminanceCheck)
    {
        return validateQRCode(outValues, true, false);
    }

    public boolean validateQRCode(Hashtable outValues, boolean localLuminanceCheck, boolean scale) {
        if (scale)
        {
            try {
                this.currentImage = Thumbnails.of(currentImage).size(275, 275).asBufferedImage();

            } catch (IOException e) {
                logger.error("Image cannot be scaled. ", e);
            }
        }

        // finding luminance of the image
        LuminanceSource lumSource = new BufferedImageLuminanceSource(currentImage);

        Binarizer qrHB;
        if (!localLuminanceCheck) {
            qrHB = new GlobalHistogramBinarizer(lumSource);
        } else {
            // creating binary bitmap from Black-White image
            qrHB = new HybridBinarizer(lumSource);
            ((HybridBinarizer) qrHB).setBLOCK_SIZE_POWER(blockSizePower);
        }
        BinaryBitmap bitmap = new BinaryBitmap(qrHB);

        try {
            currentImage = MatrixToImageWriter.toBufferedImage(bitmap.getBlackMatrix());
        } catch (NotFoundException e) {
            logger.error("cannot find any bit matrix.", e);
        }

        Hashtable<DecodeHintType, Object> hint = new Hashtable<DecodeHintType, Object>();
        hint.put(DecodeHintType.TRY_HARDER, BarcodeFormat.QR_CODE);

        QRCodeReader QRreader = new QRCodeReader();

        try {
            // decodes the QR code
            Result result = QRreader.decode(bitmap, hint);

            resultText = result.getText();
            return true;
        } catch (NotFoundException e) {
            logger.info("cannot detect any QR code (no enough finder patterns).");
            return false;
        } catch (ChecksumException e) {
            logger.info("cannot recover the QR code. Too much data errors.");
            return false;
        } catch (FormatException e) {
            logger.info("QR code cannot be decoded.");
            return false;
        } catch (FinderPatternNotFoundException e) {
            // if no Finder Pattern has been found, it may be the color of
            // QR is inverted. So we invert the QR and try one more time

            Binarizer invertHB;
            if (!localLuminanceCheck) {
                invertHB = new GlobalHistogramBinarizer(lumSource);
            } else {
                invertHB = new HybridBinarizer(lumSource);
                ((HybridBinarizer) invertHB).setBLOCK_SIZE_POWER(blockSizePower);
            }

            // get the inverted Black-White matrix
            BitMatrix invertBlackMatrix = null;
            try {
                invertBlackMatrix = invertHB.getBlackMatrix();
            } catch (NotFoundException e1) {
                logger.error(e1);
            }

            int invertWidth = currentImage.getWidth();
            int invertHeight = currentImage.getHeight();

            // flip each bit in the inverted BitMatrix
            for (int x = 0; x < invertWidth; x++) {
                for (int y = 0; y < invertHeight; y++) {
                    invertBlackMatrix.flip(x, y);
                }
            }

            currentImage = MatrixToImageWriter.toBufferedImage(invertBlackMatrix);

            // get luminance source from inverted image
            lumSource = new BufferedImageLuminanceSource(currentImage);

            Binarizer afterInvertHB;
            if (!localLuminanceCheck) {
                afterInvertHB = new GlobalHistogramBinarizer(lumSource);

            } else {
                // creating binary bitmap from Black-White image
                afterInvertHB = new HybridBinarizer(lumSource);
                ((HybridBinarizer) afterInvertHB).setBLOCK_SIZE_POWER(blockSizePower);
            }
            BinaryBitmap invertBitMap = new BinaryBitmap(afterInvertHB);

            // decoding inverted QR
            QRCodeReader invertQRreader = new QRCodeReader();

            try {
                Result invertResult = invertQRreader.decode(invertBitMap, hint);

                resultText = invertResult.getText();

                System.out.println("Out put data is: " + resultText);

                return true;
            } catch (NotFoundException e1) {
                logger.info("cannot detect any QR code (no enough finder patterns).");
                return false;
            } catch (ChecksumException e1) {
                logger.info("cannot recover the QR code. Too much data errors.");
                return false;
            } catch (FormatException e1) {
                logger.info("QR code cannot be decoded.");
                return false;
            } catch (FinderPatternNotFoundException e1) {
                logger.info("Cannot confirm where all three Finder Patterns are! ");
                return false;
            } catch (Exception e1) {
                logger.error(e1);
                return false;
            }
        } catch (Exception e) {
            logger.error(e);
            return false;
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:07:11+00:00Added an answer on May 29, 2026 at 11:07 am

    It’s not different, it’s probably that you are not using TRY_HARDER mode, or are not trying both binarizers. The online version will do those things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to decode a colored QR code in Java with ZXing library.
I am trying to decode QR code with errors in Java with ZXing library.
Trying to use Java's regexp I want to match /app, /app/.* , but not
I'm trying to use Zxing in my Android app. I've added the small library
I am trying use a Java Uploader in a ROR app (for its ease
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I am trying use javascript regular expressions to do some matching and I found
I have been trying use the edit_post_link() function to contain an image. All of
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.