• 字符串生成二维码


    implementation "com.google.zxing:core:3.3.2"
    implementation "com.journeyapps:zxing-android-embedded:3.6.0"


    fun createQRImage(
    content: String?, widthPix: Int, heightPix: Int
    ): Bitmap? {
    try {
    val hints = HashMap<EncodeHintType, Any>()
    hints[EncodeHintType.CHARACTER_SET] = StandardCharsets.UTF_8.name()
    hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L
    hints[EncodeHintType.MARGIN] = 1

    var bitMatrix: BitMatrix? = null
    try {
    bitMatrix = QRCodeWriter().encode(
    content, BarcodeFormat.QR_CODE, widthPix,
    heightPix, hints
    )
    /* bitMatrix = MultiFormatWriter().encode(
    content, BarcodeFormat.QR_CODE, widthPix, heightPix, hints
    )*/

    } catch (e: WriterException) {
    "createQRImage WriterException=$e".logD("ljj")

    }
    val pixels = IntArray(widthPix * heightPix)
    for (y in 0 until heightPix) {
    for (x in 0 until widthPix) {
    if (bitMatrix != null) {
    if (bitMatrix.get(x, y)) {
    pixels[y * widthPix + x] = -0x1000000
    } else {
    pixels[y * widthPix + x] = -0x1
    }
    } else {
    return null
    }
    }
    }
    val bitmap: Bitmap? = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888)
    bitmap!!.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix)
    return bitmap
    } catch (e: Exception) {
    "createQRImage Exception=$e".logD("ljj")
    }
    return null
    }
  • 相关阅读:
    API响应
    利用postman 实现Get和Post测试
    Postman 使用详解
    斐讯K2 22.5.9固件刷华硕固件实测教程
    Python多线程
    Ubuntu 16.04 上安装 MySQL 5.7 教程
    python 实战爬虫项目,学会这个32个项目天下无敌
    目录
    zip 下载解压
    滑动
  • 原文地址:https://www.cnblogs.com/xgjblog/p/16624549.html
Copyright © 2020-2023  润新知