Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i change contrast of an image in .net dynamically.
Scenario: I show a pic in lets say in an image control and then i want a icon or a button which adjusts the contrast for the image.
Also can i magnify certain portions of the image after a button(magnify) click.
Posted

1 solution

Magnifying is easy. You just draw the image section at a larger size. Contrast is also not hard. My image filtering articles show one way of doing it, but it's actually easier to do it using the ImageAttributes class. There's plenty of examples online, did you bother to look ?
 
Share this answer
 
Comments
coderaug 18-Aug-10 1:43am    
Yes i did, I am following this link:
http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
public static Bitmap MakeGrayscale(Bitmap original)
{
//make an empty bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);

for (int i = 0; i < original.Width; i++)
{
for (int j = 0; j < original.Height; j++)
{
//get the pixel from the original image
Color originalColor = original.GetPixel(i, j);

//create the grayscale version of the pixel
int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
+ (originalColor.B * .11));

//create the color object
Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);

//set the new image's pixel to the grayscale version
newBitmap.SetPixel(i, j, newColor);
}
}

return newBitmap;
}
I AM PASSING VALUES TO THIS METHOD AS:

protected void grayscale_Click(object sender, EventArgs e)
{
//Get the path of image file

string path = Image1.ImageUrl;

//create bitmap from path and pass as argument to function makegryscale2

Bitmap b = MakeGrayscale(new Bitmap(path.Substring(2)));

//overwrite with saving at same path

b.Save(path);

//set it imageurl

Image1.ImageUrl = path;

}
BUT it is giving me an error, the error says Invalid Parameter. plz let me know how can i use this method????
Also, can u provide me link of ur articles??
Christian Graus 27-Aug-10 1:42am    
If you searched this site or clicked on my name, you'd find my articles soon enough. If you were to tell me what line had the error, I could try to help. You should read my article, not use get/set pixel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900