Ejemplo n.º 1
0
        public BarcodeCorrection(OmrPageOutput page, OmrBarcodeField barcode)
        {
            this.m_page         = page;
            this.m_expectedArea = barcode;
            InitializeComponent();

            // Crop the image
            String tPath = Path.GetTempFileName();

            using (Bitmap bmp = new Bitmap((int)barcode.TopRight.X - (int)barcode.TopLeft.X, (int)barcode.BottomLeft.Y - (int)barcode.TopLeft.Y, PixelFormat.Format24bppRgb))
                using (Graphics g = Graphics.FromImage(bmp))
                    using (Image img = Image.FromFile(this.m_page.AnalyzedImage))
                    {
                        g.DrawImage(img, 0, 0, new Rectangle(new Point((int)barcode.TopLeft.X, (int)barcode.TopLeft.Y), bmp.Size), GraphicsUnit.Pixel);
                        bmp.Save(tPath);
                    }

            // Rotate
            using (Image img = Image.FromFile(tPath))
                using (var rotated = new AForge.Imaging.Filters.RotateBilinear(-90).Apply((Bitmap)img))
                    using (var scaled = new AForge.Imaging.Filters.ResizeBilinear((int)(rotated.Width * 0.75), (int)(rotated.Height * .75)).Apply(rotated))
                    {
                        tPath = Path.GetTempFileName();
                        scaled.Save(tPath);
                        pbBarcode.ImageLocation = tPath;
                    }
        }
Ejemplo n.º 2
0
 private Bitmap GetRotateImage(Bitmap vLast, int factor)
 {
     if (factor == 0)
     {
         return(new Bitmap(vLast));
     }
     else
     {
         AForge.Imaging.Filters.RotateBilinear m = new AForge.Imaging.Filters.RotateBilinear(factor);
         m.FillColor = Color.FromArgb(0, 254, 254, 254);
         return(m.Apply(vLast));
     }
 }
Ejemplo n.º 3
0
        //procedura obracania pliku graficznego i pliku z podglądem
        public void rotation(double ang)
        {
            //inicjalizacja filtra
            AForge.Imaging.Filters.RotateBilinear rot = new AForge.Imaging.Filters.RotateBilinear(ang);
            //otwarcie plików
            FileStream srcstream = new FileStream(pic_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            FileStream prevstream = new FileStream(Server.MapPath("~/img/prev.bmp"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //stworzenie bitmap
            Bitmap source = new Bitmap(srcstream);
            Bitmap prev = new Bitmap(prevstream);
            //użycie filtra
            source = rot.Apply(source);
            //zapisanie wyniku
            source.Save(Server.MapPath("~/img/tmp1.bmp"));
            //zwolnienie bitmapy
            ((IDisposable)source).Dispose();
            //zamknięcie strumienia
            srcstream.Close();

            prev = rot.Apply(prev);
            int resX = 0;
            int resY = 0;
            //rozróżnianie obrazów poziomych od pionowych
            if (prev.Width >= prev.Height)
            {
                resX = 200;
                resY = (int)((prev.Height * 200) / prev.Width);
            }
            else
            {
                resX = (int)((prev.Width * 200) / prev.Height);
                resY = 200;
            }
            prev.Save(Server.MapPath("~/img/prev1.bmp"));
            ((IDisposable)prev).Dispose();
            prev = null;
            prevstream.Close();
            //ustalenie rozmiarów image1
            Image1.Width = resX;
            Image1.Height = resY;
        }
Ejemplo n.º 4
0
 private Bitmap GetRotateImage(Bitmap vLast, int factor)
 {
     if (factor == 0)
         return new Bitmap(vLast);
     else
     {
         AForge.Imaging.Filters.RotateBilinear m = new AForge.Imaging.Filters.RotateBilinear(factor);
         m.FillColor = Color.FromArgb(0, 254, 254, 254);
         return m.Apply(vLast);
     }
 }