Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Android 使用Zxing库生成ean13条形码,该库下方显示代码编号_Android_Barcode_Zxing - Fatal编程技术网

Android 使用Zxing库生成ean13条形码,该库下方显示代码编号

Android 使用Zxing库生成ean13条形码,该库下方显示代码编号,android,barcode,zxing,Android,Barcode,Zxing,我正在使用Zxing库从字符串数字代码生成条形码位图,代码如下: public Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int img_width, int img_height) throws WriterException { String contentsToEncode = contents; if (contentsToEncode == null) { return nu

我正在使用Zxing库从字符串数字代码生成条形码位图,代码如下:

public Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int img_width, int img_height) throws WriterException {
    String contentsToEncode = contents;
    if (contentsToEncode == null) {
        return null;
    }
    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contentsToEncode);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result;
    try {
        result = writer.encode(contentsToEncode, format, img_width, img_height, hints);
    } catch (IllegalArgumentException iae) {
        // Unsupported format
        return null;
    }
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}

private String guessAppropriateEncoding(CharSequence contents) {
    // Very crude at the moment
    for (int i = 0; i < contents.length(); i++) {
        if (contents.charAt(i) > 0xFF) {
            return "UTF-8";
        }
    }
    return null;
}
public Bitmap encodeAsBitmap(字符串内容、条形码格式、int-img\u宽度、int-img\u高度)引发WriterException{
字符串contentsToEncode=内容;
if(contentsToEncode==null){
返回null;
}
映射提示=null;
字符串编码=猜测适当编码(contentsToEncode);
if(编码!=null){
提示=新的EnumMap(EncodeHintType.class);
put(EncodeHintType.CHARACTER\u集,编码);
}
MultiFormatWriter writer=新的MultiFormatWriter();
位矩阵结果;
试一试{
结果=writer.encode(内容编码、格式、img\u宽度、img\u高度、提示);
}捕获(IllegalArgumentException iae){
//不支持的格式
返回null;
}
int width=result.getWidth();
int height=result.getHeight();
int[]像素=新int[宽度*高度];
对于(int y=0;y0xFF){
返回“UTF-8”;
}
}
返回null;
}
它工作得很好,但它只在图像中生成条形码,其中没有数字。当我想用下面的数字在ImageView中绘制它时,问题就来了,因为我们通常在条形码中看到它们。我尝试使用textview,但它们太小或太大,这取决于屏幕和ImageView的大小

问题是,有没有办法在Zxing库的位图中包含条形码下方的代码号?或者有没有其他简单的解决方案,比如文本视图中的可调整大小的文本等等

提前谢谢