Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
bog
Contributor
bog
Posts: 35
Registered: ‎05-11-2011
My Device: 9800
My Carrier: bell

Re: ZXING Barcode Scanning API for OS 5.0

A strange issue I have now is when I try to pack the code, I have the error:

 

I/O Error: C:\Users\vml\workspace\Zxing\rim\build (Access is denied)

 

How did you guys include zxing library?  I am refering the .class files in zxing/rim/build, but I can not acess the read-only folder, although I have admin rights.

 

Thanks!

Please use plain text.
Contributor
ali_irawan
Posts: 14
Registered: ‎05-18-2011
My Device: 9300, 9700
My Carrier: T-Mobile

Re: ZXING Barcode Scanning API for OS 5.0

I suggested you copy all package from com.google.zxing (the .java, not the .classes) to your project.

 

Or you can using Ant build, I've written a blog post for this.

Until you spread your wings, You will have no idea how far you can fly
Please use plain text.
bog
Contributor
bog
Posts: 35
Registered: ‎05-11-2011
My Device: 9800
My Carrier: bell

Re: ZXING Barcode Scanning API for OS 5.0

Thanks, it compiles now.

 

It seems not be able to detect qr code, can anyone who sucessfully detected qr code point me where is the problem?

 

Here is the way I use zxing with BitmapLuminanceSource

 

Thanks!

 

 LuminanceSource source = new BitmapLuminanceSource(bmp);
 BinaryBitmap bbmap = new BinaryBitmap(new HybridBinarizer(source));
            
Hashtable hints = new Hashtable();

Vector formats = new Vector();
formats.addElement(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

Reader reader = new QRCodeReader();
Result result = reader.decode(bbmap, hints);
            


public final class BitmapLuminanceSource extends LuminanceSource {

private final Bitmap bmap ;
private int[] rgbData;

public BitmapLuminanceSource(Bitmap bmap) {
  super(bmap.getWidth(), bmap.getHeight());
  this.bmap = bmap;
}

// Instead of multiplying by 306, 601, 117, we multiply by 256, 512, 256, so that
// the multiplies can be implemented as shifts.
//
// Really, it's:
//
// return ((((pixel >> 16) & 0xFF) << 8) +
//         (((pixel >>  8) & 0xFF) << 9) +
//         (( pixel        & 0xFF) << 8)) >> 10;
//
// That is, we're replacing the coefficients in the original with powers of two,
// which can be implemented as shifts, even though changing the coefficients slightly
// alters the conversion. The difference is not significant for our purposes.
public byte[] getRow(int y, byte[] row) {
  if (y < 0 || y >= getHeight()) {
    throw new IllegalArgumentException("Requested row is outside the image: " + y);
  }
  int width = getWidth();
  if (row == null || row.length < width) {
    row = new byte[width];
  }

  if (rgbData == null || rgbData.length < width) {
    rgbData = new int[width];
  }
  bmap.getARGB(rgbData, 0, width, 0, y, width, 1);
  for (int x = 0; x < width; x++) {
    int pixel = rgbData[x];
    int luminance = (((pixel & 0x00FF0000) >> 16) +
                     ((pixel & 0x0000FF00) >>  7) +
                      (pixel & 0x000000FF       )) >> 2;
    row[x] = (byte) luminance;
  }
  return row;
}

public byte[] getMatrix() {
  int width = getWidth();
  int height = getHeight();
  int area = width * height;
  byte[] matrix = new byte[area];

  int[] rgb = new int[area];
  bmap.getARGB(rgb, 0, width, 0, 0, width, height);
  for (int y = 0; y < height; y++) {
    int offset = y * width;
    for (int x = 0; x < width; x++) {
      int pixel = rgb[offset + x];
      int luminance = (((pixel & 0x00FF0000) >> 16) +
                       ((pixel & 0x0000FF00) >>  7) +
                        (pixel & 0x000000FF       )) >> 2;
      matrix[offset + x] = (byte) luminance;
    }
  }
  return matrix;
}

}

 

Please use plain text.
bog
Contributor
bog
Posts: 35
Registered: ‎05-11-2011
My Device: 9800
My Carrier: bell

Re: ZXING Barcode Scanning API for OS 5.0

things are strange, when I snapshot screen use the code, it capture a blank picture.

How did you snapshot?

 

Bitmap bmp = new Bitmap(Display.getWidth(),Display.getHeight()); 

Display.screenshot(bmp); 

Please use plain text.
Contributor
ezequield
Posts: 16
Registered: ‎05-27-2010
My Device: any
My Carrier: any

Re: ZXING Barcode Scanning API for OS 5.0

Yes, It's working for me in OS 5.0 (decoding QR code, not sure other uses) after trying many of the codes found in this thread and combining them in different ways!! Thank you all people who posted here. I also used BarCodeReader class posted before, changed rendering hints many times and using these lasts pieces of code in the last posts: the BitmapLuminanceSource and the code in this post: http://supportforums.blackberry.com/t5/Java-Development/Take-a-snapshot-using-the-built-in-camera-of....

 

I tried in a couple of emulators Bold 8900 and Curve 9000 and a Storm real device.

 

I would remark from my code:

 

I'm not using TRY_HARDER HINT

 

I'm using QRReader (not multiformat reader)

 

Only works in this encoding "encoding=jpeg&width=1024&height=768&quality=normal" for the viewFinder in the SnapShotAPI sample application.

 

I does not work with higher or lower resolutions.

 

Regards, Ezequiel

 

 

Please use plain text.
Developer
indusBULL
Posts: 207
Registered: ‎09-10-2010
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

I know this is old thread. But this partiicular issue is bothering me from some time.

 

@zhnupy Re: ZXING Barcode Scanning API for OS 5.0

 

I get the IllegalArgumentException on getARGB as well. Not sure what can be the reason. Were you able to solve this?

Please use plain text.
Contributor
ali_irawan
Posts: 14
Registered: ‎05-18-2011
My Device: 9300, 9700
My Carrier: T-Mobile

Re: ZXING Barcode Scanning API for OS 5.0

It means that the argument you are given may wrong. You should check your BitmapLuminanceSource code

 

I have write blog, and added some link to the download sites for the sample code. Maybe you can just download the sample, run it on your computer, and then start from there, do some modifications base on your needs.

 

http://aliirawan-wen.blogspot.com/2011/05/barcode-scanner-for-blackberry-os-50.html

 

Until you spread your wings, You will have no idea how far you can fly
Please use plain text.
Developer
indusBULL
Posts: 207
Registered: ‎09-10-2010
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

[ Edited ]

Yes I've debugged code and arguments seems to be correct. 

 

4share is blocked from our company intranet. So I can not access it. Your code is for QR format. It works for me as well. But when I try to scan other types of formats, it throws the exception. 

 

Thanks

Please use plain text.
Developer
raquibulbari
Posts: 137
Registered: ‎09-30-2009
My Device: Torch 9800

Re: ZXING Barcode Scanning API for OS 5.0

when Display.screenshot(bmpScreenshot); is called it is returning a blank screen. It is not taking the screenshot of the camera preview rather taking screenshot of the displayed screen.

 

regards

----------------------
Press like if you find a message helpful
---------
Please use plain text.
Visitor
CONTUE85
Posts: 1
Registered: ‎09-24-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

Hi, i'm using zxing 1.7 to build app for RIM OS 5.0. I wanna convert a string to bitmap. My code:

 

try {
            
            QRCode qrCode = new QRCode();
            Encoder.encode("text", ErrorCorrectionLevel.L, qrCode);
            
            // From there we get the actual data matrix and convert it into a
            // bitmap
            ByteMatrix barcode = qrCode.getMatrix();
            Bitmap bitmap = BarcodeBitmap.createBitmap(barcode, BARCODE_WIDTH);

            _barcodeField.setBitmap(bitmap);

        } catch (Exception e) {
            Util.errorDialog("error encode: " + e.getMessage());
        }

 

Error: Index 21>= 21. Please help!

Please use plain text.