This project is read-only.
1
Vote

SetPixel(x,y,color) alpha misbehaves

description

I wrote a simple piece of code that changes color of icons while keeping the pixels opacity. However SetPixel(x,y,color) and SetPixel(x,y,a,color) and .ForEach((x, y, color) =>{} misbehaved as transparent pixels became much darker. SetPixel(x,y,a,r,g,b) however behaves correctly. An Image Is Attached.

Sample Code
 Brush tint = Brushes.LightGreen;
 Color tintColor = ((Color)tint.GetValue(SolidColorBrush.ColorProperty));

 WriteableBitmap wBmp = new WriteableBitmap(bmpSrc as BitmapSource);

//This Does Not Work
 wBmp.ForEach((x, y, color) =>
                {
                    //Color col = wBmp.GetPixel(x, y);
                    return Color.FromArgb(color.A, tintColor.R, tintColor.G, tintColor.B);
                }
                );

////this works
 for (int x = 0; x < bmpSrc.PixelWidth; x++)
            {
                for (int y = 0; y < bmpSrc.PixelHeight; y++)
                {
                    Color col = wBmp.GetPixel(x, y);
                     col.R = tintColor.R;
                    col.G = tintColor.G;
                     col.B = tintColor.B;
                  
                    //Only this version of SetPixel Works
                    wBmp.SetPixel(x, y, col.A, col.R, col.G, col.B);
                   ---------------------------------------------------------------------------------
                    ////These Do Not Work Either
                   //wBmp.SetPixel(x, y, col);
                   // wBmp.SetPixel(x, y, col.A, tintColor);
                   ---------------------------------------------------------------------------------
                }
            }

Update. Error was On my part, Image format was not the format expected.
If Writable Image is converted to Pbgra32. Everything works Correctly. (ConvertToPbgra32Format)

file attachments

comments