Ejemplo n.º 1
0
        private void removeBlankPlaces()
        {
            Shrink shrinkFilter = new Shrink(Color.FromArgb(255, 255, 255));
            ResizeNearestNeighbor resizeFilter = new ResizeNearestNeighbor(0, 0);

            Bitmap tempImage = shrinkFilter.Apply(_processedImage.Bitmap);

            // image dimenstoin
            int width  = _processedImage.Width;
            int height = _processedImage.Height;
            // shrinked image dimension
            int tw = tempImage.Width;
            int th = tempImage.Height;
            // resize factors
            float fx = (float)width / (float)tw;
            float fy = (float)height / (float)th;

            if (fx > fy)
            {
                fx = fy;
            }
            // set new size of shrinked image
            int nw = (int)Math.Round(fx * tw);
            int nh = (int)Math.Round(fy * th);

            resizeFilter.NewWidth  = nw;
            resizeFilter.NewHeight = nh;

            // resize image
            Bitmap tempImage2 = resizeFilter.Apply(tempImage);

            Image <Bgr, Byte> imageCV = new Image <Bgr, byte>(tempImage2);

            _processedImage = imageCV.Mat;
        }
Ejemplo n.º 2
0
        public static Bitmap Shrink(Bitmap Imagem)
        {
            Shrink filter = new Shrink();

            Imagem = Imagem.Clone(new Rectangle(0, 0, Imagem.Width, Imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Imagem = filter.Apply(Imagem);
            return(Imagem);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Crop the image's borders
        /// </summary>
        /// <param name="image">Reference to a Bitmap</param>
        private void Crop(ref System.Drawing.Bitmap image)
        {
            Shrink filter = new Shrink(Color.White);

            try
            {
                image = filter.Apply(image);
            }
            catch (Exception) { }
        }
Ejemplo n.º 4
0
        public Bitmap GetImage(bool invalidate)
        {
            if (image == null)
            {
                ClearImage();
            }

            // scale image
            if (scaleImage)
            {
                // shrink image
                Bitmap tempImage = shrinkFilter.Apply(image);

                // image dimenstoin
                int width  = image.Width;
                int height = image.Height;
                // shrinked image dimension
                int tw = tempImage.Width;
                int th = tempImage.Height;
                // resize factors
                float fx = (float)width / (float)tw;
                float fy = (float)height / (float)th;

                if (fx > fy)
                {
                    fx = fy;
                }
                // set new size of shrinked image
                int nw = (int)Math.Round(fx * tw);
                int nh = (int)Math.Round(fy * th);
                resizeFilter.NewWidth  = nw;
                resizeFilter.NewHeight = nh;

                // resize image
                Bitmap tempImage2 = resizeFilter.Apply(tempImage);

                //
                Brush whiteBrush = new SolidBrush(Color.White);

                // create graphics
                Graphics g = Graphics.FromImage(image);

                // fill rectangle
                g.FillRectangle(whiteBrush, 0, 0, width, height);

                int x = 0;
                int y = 0;

                if (nw > nh)
                {
                    y = (height - nh) / 2;
                }
                else
                {
                    x = (width - nw) / 2;
                }

                g.DrawImage(tempImage2, x, y, nw, nh);

                g.Dispose();
                whiteBrush.Dispose();

                // release temp images
                tempImage.Dispose();
                tempImage2.Dispose();
            }

            // should we repaint the control
            if (invalidate)
            {
                Invalidate();
            }

            return(image);
        }