Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

Created Unassigned: SetPixel(x,y,color) alpha misbehaves [22299]

$
0
0
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.

Sample Code
```
Brush tint = Brushes.LightGreen;
WriteableBitmap wBmp = new WriteableBitmap(bmpSrc as BitmapSource);

//This misbehaves
wBmp.ForEach((x, y, color) =>
{
Color col = wBmp.GetPixel(x, y);
Color col2 = Color.FromArgb(col.A,
((Color)tint.GetValue(SolidColorBrush.ColorProperty)).R,
((Color)tint.GetValue(SolidColorBrush.ColorProperty)).G,
((Color)tint.GetValue(SolidColorBrush.ColorProperty)).B);
return col2;
}
);
//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.B = ((Color)tint.GetValue(SolidColorBrush.ColorProperty)).B;
col.R = ((Color)tint.GetValue(SolidColorBrush.ColorProperty)).R;
col.G = ((Color)tint.GetValue(SolidColorBrush.ColorProperty)).G;
//color.Alpha = ((Color)tint.GetValue(SolidColorBrush.ColorProperty)).A;

//Only this version of SetPixel Works
wBmp.SetPixel(x, y, col.A, col.R, col.G, col.B);
---------------------------------------------------------------------------------
//This Does Not Work Either
// wBmp.SetPixel(x, y, col.A,((Color)tint.GetValue(SolidColorBrush.ColorProperty)));
---------------------------------------------------------------------------------
}
}
```

Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>