I want to adjust the contrast of an image in Windows Phone 8.1 I have found samples for Windows Phone 7 but it does not work in Windows Phone 8.1.
This is my code:
public static WriteableBitmap ChangeContrast(WriteableBitmap Bitmap,
int[] orgPixels,
double contrastValue)
{
var result = new WriteableBitmap(Bitmap.PixelWidth, Bitmap.PixelHeight);
var contrastFactor = (50f + contrastValue) / 50f;
contrastFactor *= contrastFactor;
var contrastFactorIndex = (int)(contrastFactor * 32768);
var inputPixels = Bitmap.PixelBuffer;
int[] tempPixels = new int[Bitmap.PixelBuffer.Length];
orgPixels.CopyTo(tempPixels, 0);
if (0 != Bitmap.PixelBuffer.Length)
{
for (int index = 0; index < Bitmap.PixelBuffer.Length; index++)
{
// Extract color components
var color = tempPixels[index];
var alpha = (byte)(color >> 24);
var red = (byte)(color >> 16);
var green = (byte)(color >> 8);
var blue = (byte)(color);
int ri = red - 128;
int gi = green - 128;
int bi = blue - 128;
// Multiply contrast factor
ri = (ri * contrastFactorIndex) >> 15;
gi = (gi * contrastFactorIndex) >> 15;
bi = (bi * contrastFactorIndex) >> 15;
// Transform back to range [0, 255]
ri = ri + 128;
gi = gi + 128;
bi = bi + 128;
// Clamp to byte boundaries
red = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri));
green = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi));
blue = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi));
result.SetValue[index] = (alpha << 24) | (red << 16) | (green << 8) | blue;
}
}
//additional Buffer.BlockCopy(tempPixels, 0, inputPixels, 0, tempPixels.Length);
return result;
}
The 'SetValue' was 'pixels' in the original sample but Pixels does not exist in this object on WP8.1.
What is the equivalent please?