Esempio n. 1
0
        public void FastCrop(int xc, int yc, int w, int h, ref FastColorImage result)
        {
            int x0, y0;

            /* adjust region to fit in source image */
            x0 = xc - w / 2;
            y0 = yc - h / 2;
            if (x0 < 0)
            {
                w += x0;
                x0 = 0;
            }

            if (x0 > this.Width)
            {
                x0 = this.Width;
            }
            if (y0 < 0)
            {
                h += y0;
                y0 = 0;
            }
            if (y0 > this.Height)
            {
                y0 = this.Height;
            }
            if (x0 + w > this.Width)
            {
                w = this.Width - x0;
            }
            if (y0 + h > this.Height)
            {
                h = this.Height - y0;
            }

            result.Width         = w;
            result.Height        = h;
            result.xOffset       = x0;
            result.yOffset       = y0;
            result.originalWidth = this.Width;
            result.singledata    = this.singledata;
        }
Esempio n. 2
0
        public ColorImage GenerateStrokeArea(Bitmap input, int s)
        {
            FastColorImage piece = new FastColorImage();
            double         m;
            ArrayList      list = new ArrayList();
            double         pixVal;

            DateTime start = DateTime.Now;

            //Bitmap img = new Bitmap(input.Width, input.Height);
            ColorImage cImg = new ColorImage(input.Width, input.Height);

            StreamWriter writer = null;             //new StreamWriter("new.txt");

            FastColorImage inMem = new FastColorImage(new UnsafeBitmap(input));

            for (int i = 0; i < input.Height; i++)
            {
                for (int j = 0; j < input.Width; j++)
                {
                    inMem.FastCrop(j, i, s, s, ref piece);

                    System.Drawing.Color topColor = inMem.GetColor(j, i);

                    m = Moment00(piece, topColor, writer);

                    pixVal = (255.0 * m / (piece.Width * piece.Height));

                    cImg.SetColor(j, i, Color.FromArgb((int)pixVal, (int)pixVal, (int)pixVal));
                }
            }

            //img.Save("area.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            TimeSpan duration = DateTime.Now - start;

            System.Console.WriteLine("Stroke area computed in " + duration.TotalMilliseconds + "ms");

            return(cImg);
        }