{"id":799,"date":"2020-10-06T13:41:52","date_gmt":"2020-10-06T05:41:52","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=799"},"modified":"2021-07-22T14:54:14","modified_gmt":"2021-07-22T06:54:14","slug":"android-zxing%e8%a3%bd%e4%bd%9cqr-code","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-zxing%e8%a3%bd%e4%bd%9cqr-code\/","title":{"rendered":"Android Zxing\u88fd\u4f5cQR-Code"},"content":{"rendered":"<h4>1.\u5c0e\u5165Zxing<\/h4>\n<pre><code class=\"language-Gradle line-numbers\">implementation 'com.google.zxing:core:3.4.1'\n<\/code><\/pre>\n<h4>2.\u88fd\u4f5c\u751a\u9ebc\u6a23\u5f0f\u7684Barcode<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">private fun barcodeFormatCode(content: String): Bitmap {\n     \/\/\u9078\u64c7\u8f38\u51fa\u985e\u578b\n     val barcode = BarcodeFormat.QR_CODE\n     val matrix = MultiFormatWriter().encode(content, barcode, 600, 600, null)\n     return matrix2Bitmap(matrix)\n}\n<\/code><\/pre>\n<h4>3.\u8a2d\u7f6eBarcode\u5167\u90e8\u5c6c\u6027<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">private fun matrix2Bitmap(matrix: BitMatrix): Bitmap {\n        val w = matrix.width\n        val h = matrix.height\n        val rawData = IntArray(w * h)\n\n        for (i in 0 until w) {\n            for (j in 0 until h) {\n                \/\/\u6c92\u5167\u5bb9\u7684\u984f\u8272\n                var color = Color.YELLOW\n                if (matrix.get(i, j)) {\n                    \/\/\u6709\u5167\u5bb9\u7684\u984f\u8272\n                    color = Color.BLUE\n                }\n                rawData[i + (j * w)] = color\n            }\n        }\n\n        val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)\n        bitmap.setPixels(rawData, 0, w, 0, 0, w, h)\n        return bitmap\n}\n<\/code><\/pre>\n<h4>4.\u8abf\u7528\u65b9\u6cd5\u751f\u6210<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">code.setImageBitmap(barcodeFormatCode(\"QR-Code\"))\n<\/code><\/pre>\n<h5>5.\u6548\u679c\u5c55\u793a<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/10\/120965104_1787813338024476_6110263948945793740_n.jpg\" width=\"50%\"><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5c0e\u5165Zxing implementation &#8216;com.google.zxing:core:3.4.1&#8217;  &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[13,125,69],"class_list":["post-799","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-qrcode","tag-zxing"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=799"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/799\/revisions"}],"predecessor-version":[{"id":1416,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/799\/revisions\/1416"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}