1: /// <summary>
2: /// gets the negative of the image
3: /// </summary>
4: /// <param name="OriginalImage">Image to manipulate</param>
5: /// <returns>A bitmap image</returns>
6: public static Bitmap Negative(Bitmap OriginalImage)
7: {
8: Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
9: BitmapData NewData = Image.LockImage(NewBitmap);
10: BitmapData OldData = Image.LockImage(OriginalImage);
11: int NewPixelSize = Image.GetPixelSize(NewData);
12: int OldPixelSize = Image.GetPixelSize(OldData);
13: for (int x = 0; x < NewBitmap.Width; ++x)
14: {
15: for (int y = 0; y < NewBitmap.Height; ++y)
16: {
17: Color CurrentPixel = Image.GetPixel(OldData, x, y, OldPixelSize);
18: Color TempValue = Color.FromArgb(255 - CurrentPixel.R, 255 - CurrentPixel.G, 255 - CurrentPixel.B);
19: Image.SetPixel(NewData, x, y, TempValue, NewPixelSize);
20: }
21: }
22: Image.UnlockImage(NewBitmap, NewData);
23: Image.UnlockImage(OriginalImage, OldData);
24: return NewBitmap;
25: }