You can test with Gamma formulas found on Google
For example :
{
var imgSource = image1.Source;
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = (BitmapSource)imgSource;
newFormatedBitmapSource.DestinationFormat = PixelFormats.Bgra32;
newFormatedBitmapSource.EndInit();
WriteableBitmap wb = new WriteableBitmap(newFormatedBitmapSource);
int nWidth = wb.PixelWidth;
int nHeight = wb.PixelHeight;
int nPitch = (int)(nWidth << 2);
int nSize = (int)(nPitch * nHeight);
byte[] pixelData = new byte[nSize];
int nWidthBytes = nWidth * 4;
wb.CopyPixels(pixelData, nWidthBytes, 0);
for (int nY = 0; nY < nHeight; nY++)
{
for (int nX = 0; nX < nWidth; nX++)
{
int nPos = (int)(nY * nPitch + nX * 4);
byte b = (byte)pixelData[nPos], g = (byte)pixelData[nPos + 1], r = (byte)pixelData[nPos + 2], a = (byte)pixelData[nPos + 3];
//byte nGray = Gray(r, g, b);
//b = nGray;
//g = nGray;
//r = nGray;
// > 1 : lighten, < 1 : darken
double nGamma = 2;
double nGammaCorrection = (1 / nGamma);
b = (byte)(Math.Pow((double)(b / 255.0), nGammaCorrection) * 255.0f);
g = (byte)(Math.Pow((double)(g / 255.0), nGammaCorrection) * 255.0f);
r = (byte)(Math.Pow((double)(r / 255.0), nGammaCorrection) * 255.0f);
pixelData[nPos] = b;
pixelData[nPos + 1] = g;
pixelData[nPos + 2] = r;
}
}
wb.WritePixels(new Int32Rect(0, 0, nWidth, nHeight), pixelData, nWidthBytes, 0);
image1.Source = wb;
}
// Test for gray
private byte Gray(byte nRed, byte nGreen, byte nBlue)
{
return (byte)((nRed * 299 + nGreen * 587 + nBlue * 114) / 1000);
}
Test with 2 and 0.3 :