Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. private static void Main(string[] args)
  2. {
  3.     path = @"D:\Universität\Visual Studio Projects\Console Apps\PictureInvert\PictureInvert\ae86.png";
  4.     Init();
  5. }
  6.  
  7. private static void Init()
  8. {
  9.     // Initialize Bitmap into variable bmp
  10.     bmp = new Bitmap(path);
  11.  
  12.     Invert();
  13.  
  14.     // Save the Bitmap
  15.     Save();
  16. }
  17.  
  18. private static void Save()
  19. {
  20.     string[] str = path.Split(".");
  21.     bmp.Save(str[0] + "_INV." + str[1]);
  22. }
  23.  
  24. private static void Invert()
  25. {
  26.     int w = bmp.Width;
  27.     int h = bmp.Height;
  28.  
  29.     Color color;
  30.     byte r, g, b;
  31.  
  32.     // Invert matrix
  33.     for (int y = 0; y < h; y++)
  34.     {
  35.         for (int x = 0; x < w; x++)
  36.         {
  37.             color = bmp.GetPixel(x, y);
  38.  
  39.             r = color.R;
  40.             g = color.G;
  41.             b = color.B;
  42.  
  43.             bmp.SetPixel(x, y, Color.FromArgb(255 - r, 255 - g, 255 - b));
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement