嗨,我试着在windows phone中使用WriteableBitmapEx,但是代码不是working...what,我做错了吗?
double height = image1.ActualHeight;
double width = image1.ActualWidth;
BitmapImage img = new BitmapImage(new Uri("Tulips.png", UriKind.RelativeOrAbsolute));
BitmapImage newImg = image1.Source as BitmapImage;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int grayScale = (int)((image1.writeableBmp.GetPixel(j, i).R * 0.3) + (image1.writeableBmp.GetPixel(j, i).G * 0.59) + (image1.GetPixel(j, i).B * 0.11));
Color nc = Color.FromArgb (grayScale, grayScale, grayScale);
newImg.SetPixel(j, i, nc);
}
}发布于 2012-06-25 22:06:14
您正在尝试修改BitmapImage (newImg)。您必须创建一个WriteableBitmap
var newImg = new WriteableBitmap(image1.Source);以便能够在之后修改位图图像。
然后(如果引用的是WriteableBitmapEx)应该能够直接从newImg获得grayScale表达式中的像素值
byte grayScale = Convert.ToByte((newImg.GetPixel(j, i).R * 0.3) +
(newImg.GetPixel(j, i).G * 0.59) + (newImg.GetPixel(j, i).B * 0.11));然后还有一个Color.FromArgb语句,应该看起来像这样:
Color nc = Color.FromArgb (255, grayScale, grayScale, grayScale);https://stackoverflow.com/questions/11190323
复制相似问题