3

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?

Thomas Mondel
  • 1,944
  • 3
  • 20
  • 25
  • 1
    Are you sure this isn't just a side effect of trying to merge two colors? That's a science to do correctly, simply combining the red, green and blue often does not look good. The human eye has very non-linear color perception. – Hans Passant Aug 15 '12 at 18:35
  • Yes I am sure, because I tested this issue by excluding all functionality in the MergePixelColor method. For testing purpose I simply returned the colors that are put into the method and the first color value is correct the second one is false. It has to do something with the GetPixel method extracting the data out of the WriteableBitmap. – Thomas Mondel Aug 15 '12 at 19:54
  • @ThomasMondel There seems to be an issue with the A component. (I have used version 1.0.2 for Silverlight). For example, if I set the fill color of a rectangle to #c3bcbcbc, the actual color of the rectangle is #c38f8f8f. Have not been able to take a closer look at this, but maybe it could be wortwhile to post your concern on the Writeablebitmapex Codeplex site as well (if you have not already done so). – Anders Gustafsson Aug 15 '12 at 20:53
  • Make sure you are using the latest source code of WBX and not the binary release. If the issue still exists please post it with a sample at http://writeablebitmapex.codeplex.com/workitem/list/basic – Rene Schulte Aug 16 '12 at 06:54

1 Answers1

0

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)]));
Thomas Mondel
  • 1,944
  • 3
  • 20
  • 25