WriteableBitmapEx GetPixel() returns wrong value

北慕城南 提交于 2019-12-10 19:59:34

问题


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

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.

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+

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?


回答1:


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)]));


来源:https://stackoverflow.com/questions/11974359/writeablebitmapex-getpixel-returns-wrong-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!