00001 /*------------------------------------------------------------------------ 00002 * Copyright 2009 (c) Jonas Finnemann Jensen <jopsen@gmail.com> 00003 * 00004 * This file is part of the ZBar CIL Wrapper. 00005 * 00006 * The ZBar CIL Wrapper is free software; you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser Public License as 00008 * published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * The ZBar CIL Wrapper is distributed in the hope that it will be 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser Public License 00017 * along with the ZBar CIL Wrapper; if not, write to the Free 00018 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301 USA 00020 * 00021 *------------------------------------------------------------------------*/ 00022 00023 using System; 00024 using System.Collections.Generic; 00025 using System.Text; 00026 using System.IO; 00027 using ZBar; 00028 00029 namespace Example.ImageScanner 00030 { 00035 class SimpleImageScanner 00036 { 00037 static void Main(string[] args){ 00038 //List of files to scan 00039 List<string> files = new List<string>(); 00040 00041 //Copy arguments into files (ignore this part) 00042 for(int i = 1; i < args.Length; i++){ 00043 if(args[i] == "--help" || args[i] == "-h") 00044 Console.WriteLine("Usage ./{0} [file1] [file2] [file3] ...", args[0]); 00045 else 00046 files.Add(args[i]); 00047 } 00048 if(files.Count == 0) 00049 files.Add("barcode.bmp"); 00050 00051 //Create an instance of scanner 00052 using(var scanner = new ZBar.ImageScanner()){ 00053 //We won't use caching here 00054 scanner.Cache = false; 00055 00056 //For each file that we need scanned 00057 foreach(string file in files){ 00058 Console.WriteLine("Symbols in {0}:", file); 00059 00060 //Open the file, using System.Drawing to read it 00061 System.Drawing.Image img = System.Drawing.Image.FromFile(file); 00062 00063 //Scan the image for symbols, using System.Drawing and ZBar for conversation 00064 //Please note that this is no way an efficient implementation, more optimizations 00065 //of the conversation code etc, could easily be implemented. 00066 List<Symbol> symbols = scanner.Scan(img); 00067 00068 //For each symbol we've found 00069 foreach(Symbol symbol in symbols) 00070 Console.WriteLine("\t" + symbol.ToString()); 00071 } 00072 } 00073 } 00074 } 00075 }