PC Review


Reply
Thread Tools Rate Thread

adjusting screen contrast through C# code programmatically

 
 
New Member
Join Date: Jul 2011
Posts: 2
 
      21st Jul 2011
my problem is the following :

I am making a program, which can manipulate brightness, gamma and contrast through C# code. For brightness and gamma it is ok I have achieved it through code I found in the net, but I can't for contrast. The only thing I have found by now is a CalculateRamp method, which has as input parameters (double level, double brightness, double gamma, double contrast), I know what input to give for brightness gamma and contrast ( the values from the sliders in the interface ) , but I don't know what level is for, the other problem with this method is that when I pass the calculated ramp with random "level" parameter as a parameter to the SetDeviceGammaRamp(IntPtr hDC,ref RAMP rmp) it actually changes the screen contrast, but when I move the brightness slider the changes made from the contrast slider are lost, it may be because of using the same method or I am not sure for what.

I will be very thankful to any help or ideas, no matter if they are changes of my current solution which is not full , or brand new solutions / which I would preffer , because I feel in some way unsure with this / . Thanks in advance to everybody.

Here is the code of the CalculateRamp method, as the function SetDeviceGammaRamp(...) is called by me to manipulate the contrast with the current calculated ramp, I am not sure if I have to use it in this way or not :

public static void CalculateRamp(double level, double gamma, double brightness, double contrast) {

ramp.Red = new ushort[256];
ramp.Green = new ushort[256];
ramp.Blue = new ushort[256];

gamma /= 10;
brightness = 1 + (((brightness - 50) / 100) * 65535);
contrast = 1 + ((contrast - 50) / 100);
level = 1 + ((level - 50) / 100);

for (int i = 0; i < 256; i++)
{
double value = i * 256;
value = (Math.Pow(value / 65535, 1 / gamma) * 65535) + 0.5;
value = ((((value / 65535) - 0.5) * contrast) + 0.5) * 65535;
value = value += brightness;
value *= level;
ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] = (ushort)Math.Min((double)65535, Math.Max((double)0, value));
}
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjusting active/passive window contrast in Aero PeterH Windows Vista Installation 0 20th Jan 2008 03:18 AM
Adjusting the Contrast ethnos@notell.net Windows XP MovieMaker 2 29th May 2007 02:43 PM
Adjusting Contrast =?Utf-8?B?ZnVubnl0aWdlcg==?= Windows XP MovieMaker 1 15th Jun 2006 05:36 PM
adjusting the contrast in PowerPoint Brian Microsoft Powerpoint 4 17th Aug 2003 07:38 PM
adjusting contrast (reposted) Brian Microsoft Powerpoint 1 13th Aug 2003 07:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 AM.