图像处理窗口手机 [英] image manipulation windows phone

查看:140
本文介绍了图像处理窗口手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Phone应用程式中有图片。我有一个数组包含10个值,根据这些值我设置我的对比为

I have an image in a Windows Phone app. There I have an array containing 10 values, depending on those values I am setting my contrast as

问题是当我向前滑动是完美的。

problem is when I am sliding forward it is perfect. But when reversing back image is not getting to original image.

我已经尝试过研究了很多

I have already tried and researched a lot

其实它的代码属于代码项目网站---

Actually its a code belongs to code project site---

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;
    }

我在这里使用滑块...的值改变事件。

I am here using value changed event of slider....

调试后,我发现R值在向前滑动后是连续递减的。
ex - 117,114,101,95,但是向后滑动后,R应该增加,但是它是连续递减的,如95之后是76 ....
请帮助任何人........ .....

after debugging I found that R value is continuosly decreasing after sliding forward. ex--117,114,101,95 ,but after sliding backward R should be increased but,it is decreasing continuosly like after 95 it is 76.... Please help anybody.............

推荐答案

您的contrastArray只有正值。当您移动滑块时,总是对您的对比度应用正向更改,或者您的应用崩溃。

Your contrastArray has only positive values. When you're moving the slider back, you are always applying a positive change to your contrast, or crash your app.

double[] contrastArray = { 1, 1.2, 1.3, 1.6, 1.7, 1.9, 2.1, 2.4, 2.6, 2.9 };

这大于1。

此外,这可能会使您的应用崩溃:

Also, this can crash your app:

int nIndex = (int)sliderContrast.Value-(int)this.lastslidervalue;
this.lastslidervalue=sliderContrast.value
if (nIndex == -1) return;

因为有时候更改在负面可能大于1。这意味着你得到的nIndex小于-1,然后在这里崩溃:

because sometimes the change can be larger than one in the negative side. This means that you get nIndex smaller than -1 which then crashes here:

double CFactor = contrastArray[nIndex];

但是,您可以使用此代码来获得所需的

However, you could use this code to get what you want

private void sliderContrast_ValueChanged(object sender,     RoutedPropertyChangedEventArgs<double> e)
{
    if (sliderContrast == null) return;
    double[] contrastArray = { 0.1, 0.2, 0.3, 0.4, 0.6, 1, 1.2, 1.3, 1.6, 1.7, 1.9, 2.1, 2.4, 2.6, 2.9};
    int nIndex = Convert.ToInt32(sliderContrast.Value);

    double CFactor = contrastArray[nIndex];
    //.... the rest is the same

滑块的值为Value = 5(在XAML中执行此操作),并使最大值稍大(对于添加的值进行扩展),然后右侧和左侧的更改应使对比度更高或更低上的滑块值。在我的机器上工作。 :)

And if you set the starting value for the slider to be Value = 5 (do this in XAML) and make the maximum value a bit larger (to expand for the added values), then the change to the right and to the left should get the contrast higher or lower depending on the slider value. Works on my machine. :)

这篇关于图像处理窗口手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆