Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows phone中的WriteableBitmapEx错误_C#_Silverlight_Windows Phone 7_Windows Phone 7.1 - Fatal编程技术网

C# windows phone中的WriteableBitmapEx错误

C# windows phone中的WriteableBitmapEx错误,c#,silverlight,windows-phone-7,windows-phone-7.1,C#,Silverlight,Windows Phone 7,Windows Phone 7.1,嗨,我正在尝试在windows phone中使用,但代码不起作用…我在这方面做错了什么 double height = image1.ActualHeight; double width = image1.ActualWidth; BitmapImage img = new BitmapImage(new Uri("Tulips.png", UriKind.RelativeOrAbsolute)); BitmapImage newI

嗨,我正在尝试在windows phone中使用,但代码不起作用…我在这方面做错了什么

        double height = image1.ActualHeight;
        double width = image1.ActualWidth;
        BitmapImage img = new BitmapImage(new Uri("Tulips.png", UriKind.RelativeOrAbsolute));
        BitmapImage newImg = image1.Source as BitmapImage;

        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {

                int grayScale = (int)((image1.writeableBmp.GetPixel(j, i).R * 0.3) + (image1.writeableBmp.GetPixel(j, i).G * 0.59) + (image1.GetPixel(j, i).B * 0.11));
                Color nc = Color.FromArgb (grayScale, grayScale, grayScale);
                newImg.SetPixel(j, i, nc);

            }
        }
双倍高度=图像1.实际高度;
双倍宽度=图像1.实际宽度;
BitmapImage img=新的BitmapImage(新Uri(“Tulips.png”,UriKind.RelativeOrAbsolute));
BitmapImage newImg=image1。源为BitmapImage;
对于(int i=0;i
您正在尝试修改
位图图像
newImg
)。您必须创建一个
WriteableBitmap

var newImg = new WriteableBitmap(image1.Source);
以便以后能够修改位图图像

然后(如果您正在引用WriteableBitmapEx),您应该能够直接从
newImg
获取
grayScale
表达式中的像素值:

byte grayScale = Convert.ToByte((newImg.GetPixel(j, i).R * 0.3) + 
    (newImg.GetPixel(j, i).G * 0.59) + (newImg.GetPixel(j, i).B * 0.11));
然后还有
Color.FromArgb
语句,看起来应该更像这样:

Color nc = Color.FromArgb (255, grayScale, grayScale, grayScale);

你说“不工作”是什么意思?抛出异常时,什么也没有发生,结果不是您期望的结果?您遇到了什么样的错误?
grayScale[0]
只是一个输入错误吗?顺便说一句,
Color.FromArgb()
有四个参数,表示
Alpha
通道的第一个参数。@KooKiz errors int第二个for循环。.代码不能为空complied@AndersGustafsson是的,这是一个输入错误…第二个for循环仍然不工作,它在
var newImg=new WriteableBitmap(image1.Source)中表示无效参数
Color nc=Color.FromArgb(255,灰度,灰度,灰度)它说不能从“int”转换为“byte”。没错,
FromArgb
中的参数应该是
byte
类型。使用
byte grayScale=Convert.ToByte(…)
代替在
grayScale
计算中进行转换。我将修改上面…关于构造中的错误,您是否有上面正确顺序的代码行?对于
var newImg=new WriteableBitmap(image1.Source),可能应该从
img
初始化
newImg
它表示无法从“System.Windows.Media.ImageSource”转换为“System.Windows.Media.Imaging.BitmapSource”