我在 Windows Phone 应用中有一张图片。那里我有一个包含 10 个值的数组,这取决于我将对比度设置为的值
问题是当我向前滑动时它是完美的。但是当反转图像时没有得到原始图像。
我已经尝试和研究了很多
实际上它的一个代码属于代码项目站点---
private double lastslidervalue;
private void sliderContrast_ValueChanged(object sender, MouseButtonEventArgs e)
{
if (sliderContrast == null) return;
double[] contrastArray = { 1, 1.2, 1.3, 1.6, 1.7, 1.9, 2.1, 2.4, 2.6, 2.9 };
int nIndex = (int)sliderContrast.Value-(int)this.lastslidervalue;
if (nIndex == -1)
{
int nIndex=this.lastslidervalue-sliderContrast.Value
this.lastslidervalue=sliderContrast.value
}
else
{
nIndex = (int)sliderContrast.Value-(int)this.lastslidervalue;
this.lastslidervalue=sliderContrast.value
}
double CFactor = contrastArray[nIndex];
WriteableBitmap wb;
wb = new WriteableBitmap(wbOriginal.PixelWidth, wbOriginal.PixelHeight);
//wb = new WriteableBitmap(imgOriginal);
wbOriginal.Pixels.CopyTo(wb.Pixels, 0);
int h = wb.PixelHeight;
int w = wb.PixelWidth;
for (int i = 0; i < wb.Pixels.Count(); i++)
{
int pixel = wb.Pixels[i];
int B = (int)(pixel & 0xFF); pixel >>= 8;
int G = (int)(pixel & 0xFF); pixel >>= 8;
int R = (int)(pixel & 0xFF); pixel >>= 8;
int A = (int)(pixel);
R = (int) Math.Max(0, Math.Min(255, (((R - 128) * CFactor) + 128)));
G = (int)Math.Max(0, Math.Min(255, (((G - 128) * CFactor) + 128)));
B = (int)Math.Max(0, Math.Min(255, (((B - 128) * CFactor) + 128)));
if (R > 255) R = 255; if (G > 255) G = 255; if (B > 255) B = 255;
if (R < 0) R = 0; if (G < 0) G = 0; if (B < 0) B = 0;
wb.Pixels[i] = B | (G << 8) | (R << 16) | (A << 24);
}
wb.Invalidate();
image1.Source = wb;
}
我在这里使用滑块的值更改事件....
调试后发现R值在向前滑动后不断减小。ex--117,114,101,95,但是向后滑动后R应该增加但是,它像95之后一样连续减少是76....请帮助任何人......