哪里的PixelFormats和WriteableBitmap.Lock在Silverlight3去?
-
11-09-2019 - |
题
几个月前,我建立了一些网上的样品一样的这一个从在Silverlight使用WriteableBitmap的类杰夫·普罗西斯。
今天重温他们的最新Silverlight3安装程序(3.0.40624.0),该API似乎有所改变。
我想出的一些变化。例如,WriteableBitmap的阵列存取已消失,但我发现它在新的像素属性,所以不是写作:
bmp[x]
我可以写
bmp.Pixels[x]
是否有这些调用类似的简单替换,或具有本身改变使用模式?
bmp = new WriteableBitmap(width, height, PixelFormats.Bgr32);
bmp.Lock();
bmp.Unlock();
使用更新的API任何人可以指向我的工作示例
解决方案
如果你不使用Lock
和Unlock
,只是使用WritabelBitmap(int, int)
构造会发生什么?做事情打破?
这似乎是SL3测试版和释放之间的这种API已经改变。 见重大更改文档勘误表(Silverlight 3中)
其他提示
关于在切换到新WriteableBitmap的另一个重要的细节在给出此答案一> ...因为像素格式是现在总是pbgra32,必须为每个像素的阿尔法值,否则,你就会得到一个全白画面。换句话说,该以前生成的像素值这样的代码:
byte[] components = new byte[4];
components[0] = (byte)(blue % 256); // blue
components[1] = (byte)(grn % 256); // green
components[2] = (byte)(red % 256); // red
components[3] = 0; // unused
应改为:
byte[] components = new byte[4];
components[0] = (byte)(blue % 256); // blue
components[1] = (byte)(grn % 256); // green
components[2] = (byte)(red % 256); // red
components[3] = 255; // alpha
不隶属于 StackOverflow