{"id":2696,"date":"2021-09-26T15:01:24","date_gmt":"2021-09-26T15:01:24","guid":{"rendered":"http:\/\/www.bardecode.com\/en1\/?p=2696"},"modified":"2021-09-26T15:14:02","modified_gmt":"2021-09-26T15:14:02","slug":"scan-barcode-net-stream","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/en1\/scan-barcode-net-stream\/","title":{"rendered":"How to scan a barcode from a .Net stream"},"content":{"rendered":"<p>You can read a barcode from a stream (TIF\/JPG or PDF) in C# using the following function to convert the stream into a byte array:<\/p>\n<p><code><br \/>\nprivate static byte[] StreamToByteArray(Stream input)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;byte[] buffer = new byte[16 * 1024];<br \/>\n&nbsp;&nbsp;&nbsp;using (MemoryStream ms = new MemoryStream())<br \/>\n&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int read;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((read = input.Read(buffer, 0, buffer.Length)) &gt; 0)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ms.Write(buffer, 0, read);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ms.ToArray();<br \/>\n&nbsp;&nbsp;&nbsp;}<br \/>\n}<br \/>\n<\/code><\/p>\n<p>&#8230;and then if &#8216;s&#8217; is your stream scan for the barcode with code similar to:<\/p>\n<p>SoftekBarcodeNet.BarcodeReader barcode = new SoftekBarcodeNet.BarcodeReader();<br \/>\nbyte[] data = StreamToByteArray(s);<br \/>\nint nBarCodes = barcode.ScanBarCodeFromByteArray(data);<br \/>\netc etc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can read a barcode from a stream (TIF\/JPG or PDF) in C# using the following function to convert the stream into a byte array: private static byte[] StreamToByteArray(Stream input) { &nbsp;&nbsp;&nbsp;byte[] buffer = new byte[16 * 1024]; &nbsp;&nbsp;&nbsp;using (MemoryStream ms = new MemoryStream()) &nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int read; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((read = input.Read(buffer, 0, buffer.Length)) &gt; 0)<\/p>\n<p><a href=\"https:\/\/www.bardecode.com\/en1\/scan-barcode-net-stream\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":318,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,31],"tags":[],"class_list":["post-2696","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\/2696"}],"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=2696"}],"version-history":[{"count":16,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/2696\/revisions"}],"predecessor-version":[{"id":2712,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/2696\/revisions\/2712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media\/318"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media?parent=2696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/categories?post=2696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/tags?post=2696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}