title: Can't read a QR code from camera
body: <p>EDIT:</p>
  
  <p>After playing around with it for a few hours, I came to believe that the problem is in the image quality. For example, to first image is how it came from the camera. Decoder can't read it. The second image is turned into B/W with adjusted contrast and the decoder reads it great.</p>
  
  <p><strong>Since the demo app that came with zxing is able to read the fist image off the monitor in a few seconds, I think the problem might be in some setting deep within the zxing library. It doesn't wait long enough to process the image, but spits out NotFound almost instantly.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/fbD38.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/QTrqS.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>I'm making a simple QR-reader app. Here's a screenshot.
  The top black area is a surfaceview, that shows frames from the camera. It works fine, only you can't see it in the screenshot. </p>
  
  <p>Then, when I press the button, a bitmap is taken from that surfaceview, placed on an ImageView below and is attempted to be read by the zxing library.</p>
  
  <p>Yet it will give out a NotFoundException. :/</p>
  
  <pre><code>**10-17 19:53:15.382: WARN/System.err(2238): com.google.zxing.NotFoundException
  10-17 19:53:15.382: WARN/dalvikvm(2238): getStackTrace() called but no trace available**
  </code></pre>
  
  <p>On the other hand, if I crop the qr image from this screenshot, place it into the imageview ( instead of a camera feed ) and try to decode it, it works fine. Therefor the QR image itself and its quality are OK... but then why doesn't it decode in the first scenario?</p>
  
  <p>Thanks!</p>
  
  <p><img src="https://i.stack.imgur.com/Gr0wz.jpg" alt="enter image description here"></p>
  
  <pre><code>public void dec(View v)
  {
  
  ImageView ivCam2 = (ImageView)findViewById(R.id.imageView2);
  ivCam2.setImageBitmap(bm);
  
  BitmapDrawable drawable = (BitmapDrawable) ivCam2.getDrawable();
  Bitmap bMap = drawable.getBitmap();
  
  TextView textv = (TextView) findViewById(R.id.mytext);
  
  LuminanceSource source = new RGBLuminanceSource(bMap); 
  BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
  Reader reader = new MultiFormatReader();
  try {
       Result result = reader.decode(bitmap);
       Global.text = result.getText(); 
          byte[] rawBytes = result.getRawBytes(); 
          BarcodeFormat format = result.getBarcodeFormat(); 
          ResultPoint[] points = result.getResultPoints();
          textv.setText(Global.text);
  
  } catch (NotFoundException e) {
      textv.setText("NotFoundException");
  } catch (ChecksumException e) {
      textv.setText("ChecksumException");
  } catch (FormatException e) {
      textv.setText("FormatException");
  }  
  
  }
  </code></pre>
  
  <p>how the bitmap is created:</p>
  
  <pre><code>    @Override
      public void surfaceCreated(SurfaceHolder holder) 
      {
              try
              {
                      this.camera = Camera.open();
                      this.camera.setPreviewDisplay(this.holder);
  
                      this.camera.setPreviewCallback(new PreviewCallback() {
  
                        public void onPreviewFrame(byte[] _data, Camera _camera) {
  
                          Camera.Parameters params = _camera.getParameters();
                             int w = params.getPreviewSize().width;
                             int h = params.getPreviewSize().height;
                             int format = params.getPreviewFormat();
                             YuvImage image = new YuvImage(_data, format, w, h, null);
  
                             ByteArrayOutputStream out = new ByteArrayOutputStream();
                             Rect area = new Rect(0, 0, w, h);
                             image.compressToJpeg(area, 50, out);
  
                             bm = BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
  
                        }
                      });
  
              }
              catch(IOException ioe)
              {
                      ioe.printStackTrace(System.out);
              }
      }
  </code></pre>