المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Image Brightness and Contrast change together



C# Programming
07-19-2009, 11:50 PM
Guys, I need help. Sorry for my English now,my brain just refused to work. I have an Image in PictureBox and have some filters to its process: contrast and brightness. Two trackbars controls filters changing values. When trackBar1_ValueChanged or trackBar2_ValueChanged events raises, function ApplyFilter() starts to work in different thread. When I using the brightness trackbar it changes the brightness of basic image. When I using the contrast trackbar it changes the contrast of image, But I don't know how to change the brightness and contrast together and show it in pictureBox component. For example I want to increase a brightness of an image. After that I want to increase a contrast but not of basic image, and what has turned out at brightness increase. After that I want to decrease a brightness to its basic level or lower. I don't know How to explain it clearly... If anybody have Vista you can see the same example in Vista PhotoGallery fix component. There are a lot of filters which you can apply to your image and change it back as you need. Here is a logic of my code...


Bitmap previewimage = null;
int brightness_value = 0;
int contrast_value = 0;

public PicPreviewForm(string filename)
{
previewimage = new Bitmap(Image.FromFile(filename));
pictureBox1.Image = previewimage;
}
public void ApplyFilter()
{
Bitmap bit;
bit = new Bitmap(previewimage);

if(brightness had been changed)
{
BrightnessFilter(bit, brightness_value);
}
If(contrast had been changed)
{
ContrastFilter(bit, contrast_value);
}
PictureBox.Image = bit;


}



I could apply all filters every time when I changing some trackbar but it really decrease program performance..