Example #1
0
        public System.Drawing.Bitmap ProcessImage(Bitmap srcBitmap)
        {
            int nWidth = _srcBitmap.Width;
            int nHeight = _srcBitmap.Height;

            Shelland.ImagingLibrary.Commands.SharedEffects.FloatPoint[,] fp = new Shelland.ImagingLibrary.Commands.SharedEffects.FloatPoint[nWidth, nHeight];
            Point[,] pt = new Point[nWidth, nHeight];

            Point mid = new Point();
            mid.X = nWidth / 2;
            mid.Y = nHeight / 2;

            double theta, radius;
            double newX, newY;

            for (int x = 0; x < nWidth; ++x)
                for (int y = 0; y < nHeight; ++y)
                {
                    int trueX = x - mid.X;
                    int trueY = y - mid.Y;
                    theta = Math.Atan2((trueY), (trueX));

                    radius = Math.Sqrt(trueX * trueX + trueY * trueY);

                    newX = mid.X + (radius * Math.Cos(theta + _degree * radius));
                    if (newX > 0 && newX < nWidth)
                    {
                        fp[x, y].X = newX;
                        pt[x, y].X = (int)newX;
                    }
                    else
                        fp[x, y].X = pt[x, y].X = x;

                    newY = mid.Y + (radius * Math.Sin(theta + _degree * radius));
                    if (newY > 0 && newY < nHeight)
                    {
                        fp[x, y].Y = newY;
                        pt[x, y].Y = (int)newY;
                    }
                    else
                        fp[x, y].Y = pt[x, y].Y = y;
                }

            if (_smoothing)
            {
                OffsetAntialiasCommand cmd = new OffsetAntialiasCommand(_srcBitmap, fp);
                return cmd.ProcessImage(_srcBitmap);
            }
            else
            {
                OffsetAbsCommand cmd = new OffsetAbsCommand(_srcBitmap, pt);
                return cmd.ProcessImage(_srcBitmap);
            }
        }
        public System.Drawing.Bitmap ProcessImage(Bitmap srcBitmap)
        {
            int nWidth = _srcBitmap.Width;
            int nHeight = _srcBitmap.Height;

            Shelland.ImagingLibrary.Commands.SharedEffects.FloatPoint[,] fp = new Shelland.ImagingLibrary.Commands.SharedEffects.FloatPoint[nWidth, nHeight];
            Point[,] pt = new Point[nWidth, nHeight];

            Point mid = new Point();
            mid.X = nWidth / 2;
            mid.Y = nHeight / 2;

            double newX, newY;
            double xo, yo;

            for (int x = 0; x < nWidth; ++x)
                for (int y = 0; y < nHeight; ++y)
                {
                    xo = ((double)_factor * Math.Sin(2.0 * 3.1415 * (float)y / 128.0));
                    yo = ((double)_factor * Math.Cos(2.0 * 3.1415 * (float)x / 128.0));

                    newX = (x + xo);
                    newY = (y + yo);

                    if (newX > 0 && newX < nWidth)
                    {
                        fp[x, y].X = newX;
                        pt[x, y].X = (int)newX;
                    }
                    else
                    {
                        fp[x, y].X = 0.0;
                        pt[x, y].X = 0;
                    }

                    if (newY > 0 && newY < nHeight)
                    {
                        fp[x, y].Y = newY;
                        pt[x, y].Y = (int)newY;
                    }
                    else
                    {
                        fp[x, y].Y = 0.0;
                        pt[x, y].Y = 0;
                    }
                }

            if (_smooth)
            {
                OffsetAbsCommand cmd = new OffsetAbsCommand(_srcBitmap, pt);
                _srcBitmap = cmd.ProcessImage(_srcBitmap);
            }
            else
            {
                OffsetAntialiasCommand cmd = new OffsetAntialiasCommand(_srcBitmap, fp);
                _srcBitmap = cmd.ProcessImage(_srcBitmap);
            }

            return _srcBitmap;
        }