【问题标题】:Using zxing in Blackberry 5.0在黑莓 5.0 中使用 zxing
【发布时间】:2011-05-20 03:40:51
【问题描述】:

我在 Blackberry 5.0 SDK 中实现条形码扫描时遇到了困难,因为我在互联网上进行了深度搜索,但没有发现任何线索。

然后我开始编写自己的类来提供条形码扫描(使用zxing核心) 那么我需要实现 BitmapLuminanceSource(rim 版本不是 Android 版本)

 public class BitmapLuminanceSource extends LuminanceSource {

    private final Bitmap bitmap;

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

    public byte[] getRow(int y, byte[] row) {
                //how to implement this method
        return null;
    }

    public byte[] getMatrix() {
                //how to implement this method
        return null;
    }
}

【问题讨论】:

    标签: blackberry barcode zxing


    【解决方案1】:

    好吧,LuminanceSource 中的 javadoc 告诉你它返回了什么。你在android/ 中有像PlanarYUVLuminanceSource 这样的实现,它向你展示了它的一个例子。你看过这些吗?

    不过,快速的答案是两者都返回图像的一行或整个图像,作为亮度值数组。每个像素有一个byte 值,应将其视为无符号值。

    【讨论】:

    • 是的。我看过那些。然后我实现了 BitmapLuminanceSource。当我运行项目时,它不是错误。但我无法为原始数据获得正确的值。我正在将“Hello”编码为 QR 码,但是当想要解码它返回不需要的字符(不是“Hello”)时,我仍然需要验证我的 BitmapLuminanceSource 是否实现得很好。但是感谢您的回答,一旦我解决了我的问题,我会提供更新。
    【解决方案2】:

    我已经解决了这个问题。

    这是 BitmapLuminanceSource 实现

    import net.rim.device.api.system.Bitmap;
    
    import com.google.zxing.LuminanceSource;
    
    public class BitmapLuminanceSource extends LuminanceSource {
    
    private final Bitmap bitmap;
    private byte[] matrix;
    
    public BitmapLuminanceSource(Bitmap bitmap) {
        super(bitmap.getWidth(), bitmap.getHeight());
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
    
        this.bitmap = bitmap;
    
        int area = width * height;
        matrix = new byte[area];
        int[] rgb = new int[area];
    
        bitmap.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 = (306 * ((pixel >> 16) & 0xFF) + 601
                        * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> 10;
                matrix[offset + x] = (byte) luminance;
            }
        }
    
        rgb = null;
    
    }
    
    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];
        }
    
        int offset = y * width;
        System.arraycopy(this.matrix, offset, row, 0, width);
    
        return row;
    }
    
    public byte[] getMatrix() {
        return matrix;
    }
    
    }
    

    我将 com.google.zxing(条形码编码/解码库)添加到我的项目中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多