我正在尝试使用windows phone 8中的WriteableBitmap更改图像的颜色。基本上,我有一个黑色和透明背景的图标(png)。我尝试将它转换为透明背景的白色,如下所示:
StreamResourceInfo sri = Application.GetResourceStream(new Uri(value.ToString(), UriKind.Relative));
BitmapImage src = new BitmapImage();
src.SetSource(sri.Stream);
// Get WriteableBitmap
WriteableBitmap bitmap = new WriteableBitmap(src);
// Iterate through each pixel.
for (int x = 0; x < bitmap.Pixels.Length; x++)
{
byte[] actualColorValues = BitConverter.GetBytes(bitmap.Pixels[x]);
byte[] modifiedColorValues = new byte[4];
modifiedColorValues[0] = 255;
modifiedColorValues[1] = 255;
modifiedColorValues[2] = 255;
//opacity
modifiedColorValues[3] = actualColorValues[3];
bitmap.Pixels[x] = BitConverter.ToInt32(modifiedColorValues, 0);
}
// Set Image object, defined in XAML, to the modified bitmap.
return bitmap;图像转换为白色,但它有轻微的扭曲,特别是边缘,它并不完美,特别是在边缘作为实际的图标。这是一个已知的问题,还是我遗漏了什么?
发布于 2014-01-08 12:16:45
这里有一个关于如何改变像素颜色的很好的例子here
我还将使用类似这样的方法来获得与颜色等效的int
public static int GetArgbValues(Color c)
{
string colorcode = c.ToString();
int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
return argb;
}https://stackoverflow.com/questions/16382042
复制相似问题