Beispiel #1
0
        public static Image Invert(this Image imagex)
        {
            var image  = AForge.Imaging.Image.Clone(new Bitmap(imagex), PixelFormat.Format24bppRgb);
            var filter = new Invert();

            filter.ApplyInPlace(image);

            var fastImage = new LockBitmap(image);

            fastImage.LockBits();
            var vert = 0;

            while (vert < fastImage.Height)
            {
                var hor = 0;
                while (hor < fastImage.Width)
                {
                    var color = fastImage.GetPixel(hor, vert);
                    if (color.R >= 90)
                    {
                        fastImage.SetPixel(hor, vert, Color.White);
                    }

                    hor++;
                }
                vert++;
            }
            fastImage.UnlockBits();



            return(fastImage.GetBitmap());
        }
Beispiel #2
0
        public static Bitmap ClearHorizontalBars(Bitmap imageoriginal)
        {
            LockBitmap image = new LockBitmap(imageoriginal);

            image.LockBits();
            //  var image = imageoriginal.Clone(0, 0, imageoriginal.Width, imageoriginal.Height);
            var vert = 0;

            while (vert < image.Height)
            {
                var hor = 0;
                while (hor < image.Width)
                {
                    var color = image.GetPixel(hor, vert);
                    if (color.R <= 255 && color.R >= 240 && color.G <= 255 && color.G >= 240 && color.B <= 255 &&
                        color.B >= 240)
                    {
                        image.SetPixel(hor, vert, Color.White);
                    }
                    if (!(color.R == 255 && color.B == 255 && color.G == 255) && (hor == 0))
                    {
                        for (var dotwice = -3; dotwice < 3; dotwice++)
                        {
                            for (var horclear = 0; horclear < image.Width; horclear++)
                            {
                                if (vert + dotwice < 0)
                                {
                                }
                                else
                                {
                                    if (vert + dotwice > image.Height - 1)
                                    {
                                        image.SetPixel(horclear, vert, Color.White);
                                        dotwice = 3;
                                    }
                                    else
                                    {
                                        image.SetPixel(horclear, vert + dotwice, Color.White);
                                    }
                                }
                            }
                        }
                    }
                    hor++;
                }
                vert++;
            }
            image.UnlockBits();
            return(image.GetBitmap());
        }
Beispiel #3
0
        private static ImageAndRowList DefineRows(List <Row> rowlist, Image imageX)
        {
            var vert = 0;

            var image = new LockBitmap((Bitmap)imageX.Clone());

            image.LockBits();
            while (vert < image.Height)
            {
                var hor = 0;
                while (hor < image.Width)
                {
                    var color = image.GetPixel(hor, vert);


                    if (color.R == 255 && color.G == 255 && color.B == 255)
                    {
                        image.SetPixel(hor, vert, Color.Green);

                        hor++;
                    }
                    else
                    {
                        hor = image.Width;
                    }
                }
                vert++;
            }

            for (var x = 0; x < image.Height; x++)
            {
                var color = image.GetPixel(image.Width - 1, x);

                if (color.R != 255 && color.G != 255 && color.B != 255)
                {
                    x++;
                }
                else
                {
                    var i = x - 2;
                    if (i < 0)
                    {
                        i = 0;
                    }
                    var thisrow = new Row {
                        RowTop = i
                    };
                    while (color.R == 255 && color.G == 255 && color.B == 255 && x < image.Height - 1)
                    {
                        x++;
                        color = image.GetPixel(image.Width - 1, x);
                    }

                    thisrow.RowBottom = x + 2;

                    if (thisrow.RowBottom - thisrow.RowTop > ((int)(image.Height * .0088)))
                    {
                        rowlist.Add(thisrow);
                    }
                }
            }
            image.UnlockBits();

            return(new ImageAndRowList {
                image = imageX, listrow = rowlist
            });
        }