Beispiel #1
0
        private void btn_File_Click(object sender, System.EventArgs e)
        {
            string sRes="";
            OpenFileDialog ofn=new OpenFileDialog();
            if(ofn.ShowDialog()==DialogResult.OK){
                try {
                            Reader barcodeReader=
                                new com.google.zxing.MultiFormatReader();
                            System.Drawing.Bitmap srcbitmap =
                                new System.Drawing.Bitmap(ofn.FileName.ToString()); // Make a copy of the image in the Bitmap variable
                            //make a grey bitmap of it
                            bmp_util util=new bmp_util();
                            srcbitmap = util.ConvertToGrayscale(srcbitmap);

                            RGBLuminanceSource source =
                                new RGBLuminanceSource(srcbitmap, srcbitmap.Width, srcbitmap.Height);
                            com.google.zxing.BinaryBitmap bitmap=
                                new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
                            com.google.zxing.Result result = barcodeReader.decode(bitmap);
                            System.Console.WriteLine(result.Text);
                    sRes=result.Text;
                }
                catch (com.google.zxing.ReaderException zex) {
                    sRes=zex.Message;
                    System.Console.WriteLine(zex.Message);
                }
                catch (Exception ex) {
                    sRes=ex.Message;
                    System.Console.WriteLine(ex.Message);
                }
                tb.Text=sRes;
            }
        }
Beispiel #2
0
        private void btn_File_Click(object sender, System.EventArgs e)
        {
            string         sRes = "";
            OpenFileDialog ofn  = new OpenFileDialog();

            if (ofn.ShowDialog() == DialogResult.OK)
            {
                try {
                    Reader barcodeReader =
                        new com.google.zxing.MultiFormatReader();
                    System.Drawing.Bitmap srcbitmap =
                        new System.Drawing.Bitmap(ofn.FileName.ToString());                                         // Make a copy of the image in the Bitmap variable
                    //make a grey bitmap of it
                    bmp_util util = new bmp_util();
                    srcbitmap = util.ConvertToGrayscale(srcbitmap);

                    RGBLuminanceSource source =
                        new RGBLuminanceSource(srcbitmap, srcbitmap.Width, srcbitmap.Height);
                    com.google.zxing.BinaryBitmap bitmap =
                        new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
                    com.google.zxing.Result result = barcodeReader.decode(bitmap);
                    System.Console.WriteLine(result.Text);
                    sRes = result.Text;
                }
                catch (com.google.zxing.ReaderException zex) {
                    sRes = zex.Message;
                    System.Console.WriteLine(zex.Message);
                }
                catch (Exception ex) {
                    sRes = ex.Message;
                    System.Console.WriteLine(ex.Message);
                }
                tb.Text = sRes;
            }
        }