首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为Android应用生成二维码?

如何为Android应用生成二维码?
EN

Stack Overflow用户
提问于 2012-01-10 17:23:42
回答 6查看 187.8K关注 0票数 97

我需要在我的android应用程序中创建qrcode,并且我需要一个库或源代码来让我在Android应用程序中创建QR码。

我需要的库必须:

  1. 不留下水印(如onbarcode库)
  2. 不使用web服务API创建qrcode (如Google的zxing库)
  3. 不需要第三方安装程序(如QR Droid)

我已经为iPhone (Objective-C)创建了这样的代码,但在我有时间制作自己的二维码生成器之前,我需要一个针对安卓的快速修复。这是我的第一个android项目,所以任何帮助都将不胜感激。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2012-01-10 17:29:21

你调查过ZXING吗?我已经成功地用它创建了条形码。您可以在bitcoin application src中查看完整的工作示例

代码语言:javascript
复制
// this is a small sample use of the QRCodeEncoder class from zxing
try {
    // generate a 150x150 QR code
    Bitmap bm = encodeAsBitmap(barcode_content, BarcodeFormat.QR_CODE, 150, 150);

    if(bm != null) {
        image_view.setImageBitmap(bm);
    }
} catch (WriterException e) { //eek }
票数 72
EN

Stack Overflow用户

发布于 2014-08-13 17:53:56

使用zxing,这是我创建QR的代码

代码语言:javascript
复制
 QRCodeWriter writer = new QRCodeWriter();
    try {
        BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }
        ((ImageView) findViewById(R.id.img_result_qr)).setImageBitmap(bmp);

    } catch (WriterException e) {
        e.printStackTrace();
    }
票数 102
EN

Stack Overflow用户

发布于 2015-11-16 11:01:13

也许这是一个古老的话题,但我发现这个库非常有用且易于使用

QRGen

在android中使用的示例

代码语言:javascript
复制
 Bitmap myBitmap = QRCode.from("www.example.org").bitmap();
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
票数 48
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8800919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档