Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Bitmap FilterContrastColor(Bitmap b, PomocnaStruktura p)
- {
- if (p.kontrast < -100) p.kontrast = -100;
- if (p.kontrast > 100) p.kontrast = 100;
- if (p.crvena < -255) p.crvena = -255;
- if (p.crvena > 255) p.crvena = 255;
- if (p.plava < -255) p.crvena = -255;
- if (p.plava > 255) p.crvena = 255;
- if (p.zelena < -255) p.crvena = -255;
- if (p.zelena > 255) p.crvena = 255;
- double pixel = 0;
- double nPixel;
- double contrast = (100.0 + p.kontrast) / 100.0;
- contrast *= contrast;
- double red = p.crvena;
- double green = p.zelena;
- double blue = p.plava;
- for (int i = 0; i < b.Width; i++)
- {
- for (int j = 0; j < b.Height; j++)
- {
- System.Drawing.Color color = b.GetPixel(i, j);
- double conRed, conGreen, conBlue;
- double colRed, colGreen, colBlue;
- conBlue = color.B;
- conGreen = color.G;
- conRed = color.R;
- pixel = ((((conRed / 255.0) - 0.5) * contrast) + 0.5) * 255;
- if (pixel < 0) pixel = 0;
- if (pixel > 255) pixel = 255;
- conRed = (byte)pixel;
- pixel = ((((conGreen / 255.0) - 0.5) * contrast) + 0.5) * 255;
- if (pixel < 0) pixel = 0;
- if (pixel > 255) pixel = 255;
- conGreen = (byte)pixel;
- pixel = ((((conBlue / 255.0) - 0.5) * contrast) + 0.5) * 255;
- if (pixel < 0) pixel = 0;
- if (pixel > 255) pixel = 255;
- conBlue = (byte)pixel;
- nPixel = conRed + red;
- nPixel = Math.Max(nPixel, 0);
- colRed = (byte)Math.Min(255, nPixel);
- nPixel = conGreen + green;
- nPixel = Math.Max(nPixel, 0);
- colGreen = (byte)Math.Min(255, nPixel);
- nPixel = conBlue + blue;
- nPixel = Math.Max(nPixel, 0);
- colBlue = (byte)Math.Min(255, nPixel);
- b.SetPixel(i, j, System.Drawing.Color.FromArgb((int)colRed, (int)colGreen, (int)colBlue));
- }
- }
- return b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement