WriteableBitmapEx GetPixel()返回错误的值 [英] WriteableBitmapEx GetPixel() returns wrong value

查看:114
本文介绍了WriteableBitmapEx GetPixel()返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要组合来自两个WriteableBitmap对象的两个颜色值,并使用它们进行计算.因此,我在第一个对象上运行一个ForEach循环,并将其颜色值和第二个对象的颜色值解析为一个方法.

I need to combine two color values from two WriteableBitmap objects and compute something with them. Therefore I run a ForEach loop on the first object and parse its color value and the color value of the second object into a method.

writeableBitmap.ForEach((x, y, color) => 
    MergePixelColor(color, mergedWriteableBitmap.GetPixel(x, y)));

我直接从委托获得第一个值,但是要访问第二个颜色值,我使用WriteableBitmap扩展中的GetPixel方法.

The first value I get directly from the delegate, but to access the second color value I use the GetPixel method from the WriteableBitmap extension.

这实际上应该像那样工作,但是似乎GetPixel方法返回错误的数据(颜色以某种方式错误地黄色"或红色").

This should actually work just like that, but it seems that the GetPixel method returns wrong data (the colors are somehow incorrectly "yellow-ish" or "red-ish").

我抬起头来,发现了以下文章:

I looked up and found the following article:

http://forums.silverlight.net/t/250392. aspx/1?WriteableBitmap + GetPixel +

这里提到图像格式可能有问题.我的问题是,尽管我无法直接访问生成图像的位置.我从Web服务中提取了它们,但我不知道该部分是否可以改编(至少不能从我这里改编).

There it is mentioned that there might be a problem with the image format. My Problem is though that I do not have direct access to the point where the images are generated. I extract them from a webservice and I dont know if that part can be adapted (at least not from me).

我的问题是,现在是否有其他方法或解决方法来解决此问题?你有什么主意吗?

My question is now, if there is any other way or workaround to fix this issue? Do you have any ideas?

推荐答案

该解决方案可能只是一种解决方法,但是我无法在给定的时间内提出更好的解决方案.我只是事先循环了mergedWriteableBitmap并将其颜色值保存到字典中:

This solution might just be a workaround, but I couldnt come up with something better in my given time. I just loop the mergedWriteableBitmap beforehand and save its color values into a dictionary:

IDictionary<int, Color> mergedWriteableBitmapMapping = new Dictionary<int, Color>();
mergedWriteableBitmap.ForEach((x, y, color) =>
{
    int index = GetIndex(x, y, mergedWriteableBitmap.PixelWidth);
    mergedWriteableBitmapMapping.Add(index, color);
    return color;
});

然后,我使用此字典值将正确的颜色值解析为方法:

Afterwards I use this dictionary values to parse the correct color values into the method:

writeableBitmap.ForEach((x, y, color) => 
    MergePixelColor(color, mergedWriteableBitmapMapping[GetIndex(x, y, mergedWriteableBitmap.PixelWidth)]));

这篇关于WriteableBitmapEx GetPixel()返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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