我正在尝试在Silverlight3 RTM中使用新的WriteableBitmap,但是我失败了..在测试期间,所有使用过的示例和演示都无法工作。我明白他们已经稍微改变了类接口,例如删除了锁定和释放方法(仍然在官方文档页面中记录),并且还改变了构造函数(没有更多像素格式作为参数,所有位图将从32位我的理解)。Silverlight 3 WriteableBitmap问题
任何人都能成功地运行一个例子吗?这里有一个简约的例子(我在一些论坛中发现它,并稍加修改);它不工作,没有位图显示
是的,我打电话给它..这里有一个最小的例子(我发现在网上,稍微修改它);它不起作用,我得到一个空白页面(XAML包含一个名为inputImage的图像控件)。
int imageWidth = 100;
int imageHeight = 100;
//Create the bitmap
WriteableBitmap b = new WriteableBitmap(imageWidth, imageHeight);
for (int x = 0; x < imageWidth; x++)
{
for (int y = 0; y < imageHeight; y++)
{
// generate a color in 32bit format
byte[] components = new byte[4];
components[0] = (byte)(x % 255); // blue
components[1] = (byte)(y % 255); // green
components[2] = (byte)(x * y % 255); // red
components[3] = 0; // unused
int pixelValue = BitConverter.ToInt32(components, 0);
// Set the value for the
b.Pixels[y * imageWidth + x] = pixelValue;
}
}
b.Invalidate();
inputImage.Source = b;
感谢您的帮助 里卡多