示例#1
0
        static public Bitmap rotate(Bitmap image, int angle)
        {
            LockBitmap lockImage  = new LockBitmap(image);
            Bitmap     result     = new Bitmap(width: image.Width, height: image.Height);
            LockBitmap lockResult = new LockBitmap(result);

            lockImage.LockBits();
            lockResult.LockBits();

            // center of image
            int y0 = image.Height / 2;
            int x0 = image.Width / 2;

            double degree = Math.PI * angle / 180.0;

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    int newX = Convert.ToInt32(Math.Cos(degree) * (x - x0) - Math.Sin(degree) * (y - y0) + x0);
                    if (newX >= image.Width || newX < 0)
                    {
                        continue;
                    }
                    int newY = Convert.ToInt32(Math.Sin(degree) * (x - x0) + Math.Cos(degree) * (y - y0) + y0);
                    if (newY >= image.Height || newY < 0)
                    {
                        continue;
                    }
                    Color color = lockImage.GetPixel(x, y);
                    lockResult.SetPixel(newX, newY, color);
                }
            }
            lockImage.UnlockBits();
            lockResult.UnlockBits();
            return(result);
        }
示例#2
0
        static public Bitmap wind(Bitmap image, int strength, Direction direction)
        {
            int        pixelStrenght = strengthToPixels(strength, image, direction.orientation());
            Random     randShift     = new Random(pixelStrenght);
            Bitmap     result        = new Bitmap(width: image.Width, height: image.Height);
            LockBitmap lockResult    = new LockBitmap(result);
            LockBitmap lockBitmap    = new LockBitmap(image);

            lockBitmap.LockBits();
            lockResult.LockBits();

            switch (direction)
            {
            case Direction.Left:

                for (int y = lockBitmap.Height - 1; y >= 0; y--)
                {
                    for (int x = 0; x < lockBitmap.Width; x++)
                    {
                        Color cl    = lockBitmap.GetPixel(x, y);
                        int   shift = x - randShift.Next(0, strength);

                        for (int i = shift; (i <= x && i >= 0); i++)
                        {
                            lockResult.SetPixel(i, y, cl);
                        }
                    }
                }
                break;

            case Direction.Right:
                for (int y = lockBitmap.Height - 1; y >= 0; y--)
                {
                    for (int x = lockBitmap.Width - 1; x >= 0; x--)
                    {
                        Color cl    = lockBitmap.GetPixel(x, y);
                        int   shift = x + randShift.Next(0, strength);

                        for (int i = x; (i <= shift && i < lockBitmap.Width); i++)
                        {
                            lockResult.SetPixel(i, y, cl);
                        }
                    }
                }
                break;

            case Direction.Down:
                for (int x = 0; x < lockBitmap.Width; x++)
                {
                    for (int y = lockBitmap.Height - 1; y >= 0; y--)
                    {
                        Color cl    = lockBitmap.GetPixel(x, y);
                        int   shift = y + randShift.Next(0, strength);

                        for (int i = y; (i <= shift && i < lockBitmap.Height); i++)
                        {
                            lockResult.SetPixel(x, i, cl);
                        }
                    }
                }
                break;

            case Direction.Up:
                for (int x = 0; x < lockBitmap.Width; x++)
                {
                    for (int y = 0; y < lockBitmap.Height; y++)
                    {
                        Color cl    = lockBitmap.GetPixel(x, y);
                        int   shift = y - randShift.Next(0, strength);

                        for (int i = shift; (i <= y && i >= 0); i++)
                        {
                            lockResult.SetPixel(x, i, cl);
                        }
                    }
                }
                break;
            }
            lockBitmap.UnlockBits();
            lockResult.UnlockBits();
            return(result);
        }