![](/img/trans.png)
[英]Changing a Windows Phone Application's WritableBitmap Object
[英]WritableBitmap issue when changing the color
我正在尝试使用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;
图像会转换为白色,但尤其是边缘会稍微失真,特别是在边缘(作为实际图标)时并不完美。 这是一个已知问题,还是我缺少什么?
有一个很好的例子, 她如何改变像素颜色Ë
我也将使用这样的方法来获得与颜色相等的int
public static int GetArgbValues(Color c)
{
string colorcode = c.ToString();
int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
return argb;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.