In this article I will show you how to apply brightness of an image using c#.net. You can adjust the color components of the image from the input ranges between -255 and 255. You need to pass the bitmap image and input parameter (brightness) for the function. The function has image processing algorithms,it process with the RGB values and it will return the bitmap object as output.
public static Bitmap SetBrightness(Bitmap btmap, int brightness)
{
Bitmap temp = (Bitmap)btmap;
Bitmap bmap = (Bitmap)temp.Clone();
if (brightness < -255) brightness = -255;
if (brightness > 255) brightness = 255;
Color c;
for (int i = 0; i < bmap.Width; i++)
{
for (int j = 0; j < bmap.Height; j++)
{
c = bmap.GetPixel(i, j);
int cR = c.R + brightness;
int cG = c.G + brightness;
int cB = c.B + brightness;
if (cR < 0) cR = 1;
if (cR > 255) cR = 255;
if (cG < 0) cG = 1;
if (cG > 255) cG = 255;
if (cB < 0) cB = 1;
if (cB > 255) cB = 255;
bmap.SetPixel(i, j, Color.FromArgb((byte)cR, (byte)cG, (byte)cB));
}
}
return (Bitmap)bmap.Clone(); }
Post your comments / questions
Recent Article
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
Related Article