Пример #1
0
        private Image ColorToBinary(Image img)
        {
            Bitmap   bmp   = new Bitmap(img);
            Bitmap32 bmp32 = new Bitmap32(bmp);

            bmp32.LockBitmap();
            //bmp32.ToBlackWhite();
            int of = bmp32.Offset();

            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    bmp32.DrawOutLine(x, y, of);
                }
            }
            bmp32.UnlockBitmap();
            //float[][] TempMatrix = {
            //          new float[] {.3f, .3f, .3f, 0, 0},
            //           new float[] {.59f, .59f, .59f, 0, 0},
            //           new float[] {.11f, .11f, .11f, 0, 0},
            //           new float[] {0, 0, 0, 1, 0},
            //           new float[] {0, 0, 0, 0, 1}
            //};
            //ColorMatrix cmatrix = new ColorMatrix(TempMatrix);
            //Graphics gp = Graphics.FromImage(img);
            //ImageAttributes imgAttri = new ImageAttributes();
            //imgAttri.SetColorMatrix(cmatrix);
            //gp.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttri);
            return(bmp);
        }
Пример #2
0
        public void cutChar(Bitmap img)
        {
            Graphics gp    = Graphics.FromImage(img);
            Bitmap32 bmp32 = new Bitmap32(img);

            System.Drawing.Imaging.PixelFormat format = new System.Drawing.Imaging.PixelFormat();
            Point top, left, bot, right, prect;

            bmp32.LockBitmap();
            top   = bmp32.TopPoint();
            left  = bmp32.LeftPoint();
            bot   = bmp32.BotPoint();
            right = bmp32.RightPoint();
            //bmp32.Vector();
            int of = bmp32.Offset();

            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    bmp32.DrawOutLine(x, y, of);
                }
            }
            bmp32.UnlockBitmap();
            prect = new Point(left.X, top.Y);
            Rectangle rect = new Rectangle(prect, new Size(right.X - left.X, bot.Y - top.Y));
            Bitmap    clone = img.Clone(rect, format);

            gp.DrawRectangle(new Pen(Color.Green), rect);
            picFitter.Image = clone;
        }