title: Reading DataMatrix/QR code zxing java
body: <p>The below data matrix is being read well using Barcode Scanner, zxing mobile app. However, the same is not being read by zxing java library.</p>
  
  <p>I have some image transformation code commented. Even transforming the image, rotation or scaling doesn't help.</p>
  
  <p>Ideally, I would like to perform all possible image pre-processing programatically until decoded.</p>
  
  <p>What is the logic the mobile app using, since am scanning the same image from the computer screen and it is working.</p>
  
  <p>Please find below, the code am using for decoding.</p>
  
  <pre><code>public class BarcodeReader {
  
      private static Map&lt;DecodeHintType,Object&gt; hintsMap;
  
      public static void main(String...args){
  
           BufferedImage before = null;
           hintsMap = new EnumMap&lt;DecodeHintType, Object&gt;(DecodeHintType.class);
           hintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
           hintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
           //hintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
           try 
           {
               before = ImageIO.read(new File("C:/ocr.jpg"));
               decode(before);
              /* for(int i=1; i &lt; 1000;i++){
                   AffineTransform transform = new AffineTransform();
                   double rad = (double)i/100;
                   double scale = (double)i/100;
                   System.out.println("rad "+scale);
                   //transform.rotate(rad, before.getWidth()/2, before.getHeight()/2);
                   transform.scale(scale, scale);
                   BufferedImage after = new BufferedImage(before.getWidth(), before.getHeight(), BufferedImage.TYPE_INT_ARGB);
                   AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
                   after = op.filter(before, after);
                   decode(after);
               }*/
  
  
               //tmpBfrImage = tmpBfrImage.getSubimage(200, 100, 800, 800);
           } 
           catch (IOException tmpIoe) 
           {
               tmpIoe.printStackTrace();
           }
  
  
      }
  
      public static void decode(BufferedImage tmpBfrImage){
          if (tmpBfrImage == null)
              throw new IllegalArgumentException("Could not decode image.");
          LuminanceSource tmpSource = new BufferedImageLuminanceSource(tmpBfrImage);
          BinaryBitmap tmpBitmap = new BinaryBitmap(new HybridBinarizer(tmpSource));
          MultiFormatReader tmpBarcodeReader = new MultiFormatReader();
  
          Result tmpResult;
          String tmpFinalResult;
          try 
          {
              if (hintsMap != null &amp;&amp; ! hintsMap.isEmpty())
                  tmpResult = tmpBarcodeReader.decode(tmpBitmap, hintsMap);
              else
                  tmpResult = tmpBarcodeReader.decode(tmpBitmap);
              // setting results.
              tmpFinalResult = String.valueOf(tmpResult.getText());
              System.out.println(tmpFinalResult);
              System.exit(0);;
          } 
          catch (Exception tmpExcpt) 
          {
           tmpExcpt.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/tjirE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tjirE.jpg" alt="Sample Barcode"></a></p>