{"id":404,"date":"2020-05-11T16:39:28","date_gmt":"2020-05-11T08:39:28","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=404"},"modified":"2020-05-19T13:08:19","modified_gmt":"2020-05-19T05:08:19","slug":"github-%e5%a5%bd%e7%94%a8%e5%88%86%e4%ba%abandroid-zxingbarcode","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/github-%e5%a5%bd%e7%94%a8%e5%88%86%e4%ba%abandroid-zxingbarcode\/","title":{"rendered":"Github \u597d\u7528\u5206\u4eabAndroid zxing(Barcode)"},"content":{"rendered":"<h3>1.\u5148\u5c0e\u5165\u51fd\u793a\u5eab(build.gradle: Module)<\/h3>\n<pre><code class=\"language-Gradle line-numbers\">dependencies {\n     implementation 'com.contrarywind:Android-PickerView:4.1.9'\n}\n<\/code><\/pre>\n<h3>2.\u8a2d\u5b9a\u689d\u78bc\u683c\u5f0f\u4ee5\u53ca\u5927\u5c0f<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun barcodeFormatCode(num: String) : Bitmap {\n    val barcode = BarcodeFormat.CODE_128\n    val matrix = MultiFormatWriter().encode(num, barcode, 800, 160, null)\n    return bitMatrixToBitmap(matrix)\n}\n<\/code><\/pre>\n<h3>3.\u5275\u5efa\u689d\u78bc\u7684\u5716\u7247<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">private fun bitMatrixToBitmap(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            var color = Color.WHITE;\n            if (matrix.get(i, j)) {\n                \/\/ \u6709\u5185\u5bb9\u7684\u90e8\u5206\uff0c\u989c\u8272\u8bbe\u7f6e\u4e3a\u9ed1\u8272\uff0c\u53ef\u4ee5\u81ea\u5df1\u4fee\u6539\u6210\u5176\u4ed6\u989c\u8272\n                color = Color.BLACK;\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<h3>5.\u8abf\u7528\u65b9\u6cd5\u4e26\u8a2d\u7f6e\u5230ImageView\u4e0a<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">barcode.setImageBitmap(barcodeFormatCode(\"123123\"))\n<\/code><\/pre>\n<h3>6.\u6548\u679c\u5c55\u793a<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/05\/21.jpg\" alt=\"\" \/><\/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.\u5148\u5c0e\u5165\u51fd\u793a\u5eab(build.gradle: Module) dependencies { implement &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":[57],"tags":[56,15,69],"class_list":["post-404","post","type-post","status-publish","format-standard","hentry","category-github","tag-github","tag-kotlin","tag-zxing"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/404","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=404"}],"version-history":[{"count":4,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":434,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/404\/revisions\/434"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}