{"id":2684,"date":"2021-08-31T14:23:23","date_gmt":"2021-08-31T14:23:23","guid":{"rendered":"http:\/\/www.bardecode.com\/en1\/?p=2684"},"modified":"2021-08-31T14:23:23","modified_gmt":"2021-08-31T14:23:23","slug":"using-softek-barcode-reader-toolkit-android-scanbarcodefromrgbabitmap","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/en1\/using-softek-barcode-reader-toolkit-android-scanbarcodefromrgbabitmap\/","title":{"rendered":"Using the Softek Barcode Reader Toolkit on Android with ScanBarCodeFromRGBABitmap"},"content":{"rendered":"<p>The Android version of the SDK cannot read directly from image files but it can read from a bitmap using code similar to the following:<\/p>\n<pre>Barcode barcode = new Barcode();\r\n\r\n\/\/ Load your image file into a bitmap\r\n\r\nint width = bitmap.getWidth();\r\nint height = bitmap.getHeight();\r\n\r\nbyte[] rawBytes = new byte[width * height * 4];\r\nint index = 0;\r\n\r\nfor (int y = 0; y &lt; height; y++) {\r\n    for (int x = 0; x &lt; width; x++) {\r\n        int colour = bitmap.getPixel(x, y);\r\n        int red = (colour &gt;&gt; 16) &amp; 0xff;\r\n        int green = (colour &gt;&gt; 8) &amp; 0xff;\r\n        int blue = colour &amp; 0xff;\r\n        int alpha = 0;\r\n        int rawIndex = index * 4\r\n        rawBytes[rawIndex++] = (byte) red ;\r\n        rawBytes[rawIndex++] = (byte) green;\r\n        rawBytes[rawIndex++] = (byte) blue;\r\n        rawBytes[rawIndex++] = (byte) alpha;\r\n\r\n        index++;\r\n    }\r\n}\r\n\r\n<\/pre>\n<pre>int n = barcode.ScanBarCodeFromRGBABitmap(bitmap.getWidth(), bitmap.getHeight(), rawBytes);\r\n\r\nif (n &gt; 0)\r\n    strBarcode = barcode.GetBarString(1);<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Android version of the SDK cannot read directly from image files but it can read from a bitmap using code similar to the following: Barcode barcode = new Barcode(); \/\/ Load your image file into a bitmap int width = bitmap.getWidth(); int height = bitmap.getHeight(); byte[] rawBytes = new byte[width * height * 4];<\/p>\n<p><a href=\"https:\/\/www.bardecode.com\/en1\/using-softek-barcode-reader-toolkit-android-scanbarcodefromrgbabitmap\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":309,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,31],"tags":[],"class_list":["post-2684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledge-base","category-software-development-kits"],"_links":{"self":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/2684"}],"collection":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/comments?post=2684"}],"version-history":[{"count":1,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/2684\/revisions"}],"predecessor-version":[{"id":2685,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/2684\/revisions\/2685"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media\/309"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media?parent=2684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/categories?post=2684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/tags?post=2684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}