1: /// <summary>
2: /// Does a "wave" effect on the image
3: /// </summary>
4: /// <param name="OriginalImage">Image to manipulate</param>
5: /// <param name="Amplitude">Amplitude of the sine wave</param>
6: /// <param name="Frequency">Frequency of the sine wave</param>
7: /// <param name="XDirection">Determines if this should be done in the X direction</param>
8: /// <param name="YDirection">Determines if this should be done in the Y direction</param>
9: /// <returns>A bitmap which has been modified</returns>
10: public static Bitmap SinWave(Bitmap OriginalImage, float Amplitude, float Frequency, bool XDirection, bool YDirection)
11: {
12: Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
13: BitmapData NewData = Image.LockImage(NewBitmap);
14: BitmapData OldData = Image.LockImage(OriginalImage);
15: int NewPixelSize = Image.GetPixelSize(NewData);
16: int OldPixelSize = Image.GetPixelSize(OldData);
17: for (int x = 0; x < NewBitmap.Width; ++x)
18: {
19: for (int y = 0; y < NewBitmap.Height; ++y)
20: {
21: double Value1 = 0;
22: double Value2 = 0;
23: if (YDirection)
24: Value1 = System.Math.Sin(((x * Frequency) * System.Math.PI) / 180.0d) * Amplitude;
25: if (XDirection)
26: Value2 = System.Math.Sin(((y * Frequency) * System.Math.PI) / 180.0d) * Amplitude;
27: Value1 = y - (int)Value1;
28: Value2 = x - (int)Value2;
29: while (Value1 < 0)
30: Value1 += NewBitmap.Height;
31: while (Value2 < 0)
32: Value2 += NewBitmap.Width;
33: while (Value1 >= NewBitmap.Height)
34: Value1 -= NewBitmap.Height;
35: while (Value2 >= NewBitmap.Width)
36: Value2 -= NewBitmap.Width;
37: Image.SetPixel(NewData, x, y,
38: Image.GetPixel(OldData, (int)Value2, (int)Value1, OldPixelSize),
39: NewPixelSize);
40: }
41: }
42: Image.UnlockImage(NewBitmap, NewData);
43: Image.UnlockImage(OriginalImage, OldData);
44: return NewBitmap;
45: }