.net - Changing image contrast with GDI+ and C# -


my problem following :

i making program, can manipulate brightness, gamma , contrast through c# code. brightness , gamma ok. have achieved through code found in net, can't contrast.

the thing have found calculateramp method, has input parameters (double level, double brightness, double gamma, double contrast). know input give brightness, gamma , contrast (the values sliders in interface), don't know level for.

the other problem method when pass calculated ramp random level parameter parameter setdevicegammaramp(intptr hdc,ref ramp rmp) changes screen contrast, when move brightness slider changes made contrast slider lost. may because of using same method or not sure what.

i thankful or ideas, no matter if changes current solution not full, or brand new solution - prefer - because feel in way unsure this. in advance everybody.

here code of calculateramp method, function setdevicegammaramp(...) called me manipulate contrast current calculated ramp. not sure if have use in 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);      (int = 0; < 256; i++)     {         double value = * 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); } 

try taking @ this article. color matrix shows how manipulate both brightness , contrast.

this article might interest you, though think method used in article slower matrix.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -