Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public static Bitmap FilterContrastColor(Bitmap b, PomocnaStruktura p)
  2. {
  3. if (p.kontrast < -100) p.kontrast = -100;
  4. if (p.kontrast > 100) p.kontrast = 100;
  5. if (p.crvena < -255) p.crvena = -255;
  6. if (p.crvena > 255) p.crvena = 255;
  7. if (p.plava < -255) p.crvena = -255;
  8. if (p.plava > 255) p.crvena = 255;
  9. if (p.zelena < -255) p.crvena = -255;
  10. if (p.zelena > 255) p.crvena = 255;
  11.  
  12. double pixel = 0;
  13. double nPixel;
  14. double contrast = (100.0 + p.kontrast) / 100.0;
  15. contrast *= contrast;
  16. double red = p.crvena;
  17. double green = p.zelena;
  18. double blue = p.plava;
  19.  
  20. for (int i = 0; i < b.Width; i++)
  21. {
  22. for (int j = 0; j < b.Height; j++)
  23. {
  24. System.Drawing.Color color = b.GetPixel(i, j);
  25.  
  26. double conRed, conGreen, conBlue;
  27. double colRed, colGreen, colBlue;
  28.  
  29. conBlue = color.B;
  30. conGreen = color.G;
  31. conRed = color.R;
  32.  
  33. pixel = ((((conRed / 255.0) - 0.5) * contrast) + 0.5) * 255;
  34. if (pixel < 0) pixel = 0;
  35. if (pixel > 255) pixel = 255;
  36. conRed = (byte)pixel;
  37.  
  38. pixel = ((((conGreen / 255.0) - 0.5) * contrast) + 0.5) * 255;
  39. if (pixel < 0) pixel = 0;
  40. if (pixel > 255) pixel = 255;
  41. conGreen = (byte)pixel;
  42.  
  43. pixel = ((((conBlue / 255.0) - 0.5) * contrast) + 0.5) * 255;
  44. if (pixel < 0) pixel = 0;
  45. if (pixel > 255) pixel = 255;
  46. conBlue = (byte)pixel;
  47.  
  48. nPixel = conRed + red;
  49. nPixel = Math.Max(nPixel, 0);
  50. colRed = (byte)Math.Min(255, nPixel);
  51.  
  52. nPixel = conGreen + green;
  53. nPixel = Math.Max(nPixel, 0);
  54. colGreen = (byte)Math.Min(255, nPixel);
  55.  
  56. nPixel = conBlue + blue;
  57. nPixel = Math.Max(nPixel, 0);
  58. colBlue = (byte)Math.Min(255, nPixel);
  59.  
  60. b.SetPixel(i, j, System.Drawing.Color.FromArgb((int)colRed, (int)colGreen, (int)colBlue));
  61. }
  62. }
  63. return b;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement