Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Blackberry 5.0中使用zxing_Blackberry_Barcode_Zxing - Fatal编程技术网

在Blackberry 5.0中使用zxing

在Blackberry 5.0中使用zxing,blackberry,barcode,zxing,Blackberry,Barcode,Zxing,在Blackberry 5.0 SDK中实现条形码扫描时,我被绊倒了,因为我正在互联网上进行深度搜索,但没有发现任何线索 然后我开始编写自己的类来提供条形码扫描(使用zxing核心) 然后我需要实现BitmapLuminanceSource(rim版本而非Android版本) 嗯,inLuminanceSource告诉您它返回什么。在android/中有类似PlanarYUVLuminanceSource的实现,它们向您展示了一个实际的例子。你看过这些吗 不过,快速的答案是,两者都返回图像的一行

在Blackberry 5.0 SDK中实现条形码扫描时,我被绊倒了,因为我正在互联网上进行深度搜索,但没有发现任何线索

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

嗯,in
LuminanceSource
告诉您它返回什么。在
android/
中有类似
PlanarYUVLuminanceSource
的实现,它们向您展示了一个实际的例子。你看过这些吗


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

我已经解决了这个问题

下面是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;
}

}
导入net.rim.device.api.system.Bitmap;
导入com.google.zxing.LuminanceSource;
公共类BitmapLuminanceSource扩展了LuminanceSource{
私有最终位图;
私有字节[]矩阵;
公共位图亮度源(位图){
super(bitmap.getWidth(),bitmap.getHeight());
int width=bitmap.getWidth();
int height=bitmap.getHeight();
this.bitmap=位图;
内部面积=宽度*高度;
矩阵=新字节[区域];
int[]rgb=新的int[面积];
getARGB(rgb,0,宽度,0,0,宽度,高度);
对于(int y=0;y>16)和0xFF)+601
*((像素>>8)和0xFF)+117*(像素和0xFF))>>10;
矩阵[偏移量+x]=(字节)亮度;
}
}
rgb=null;
}
公共字节[]getRow(整数y,字节[]行){
如果(y<0 | | y>=getHeight()){
抛出新的IllegalArgumentException(
“请求的行位于图像外部:”+y);
}
int width=getWidth();
if(row==null | | row.length

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

是。我已经看过了。然后我实现了BitmapLuminanceSource。当我运行项目时,它不是错误。但我无法为原始数据获取正确的值。我将“Hello”编码为QR码,但当需要解码时,它会返回不需要的字符(不是“Hello”),我仍然需要验证我的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;
}

}