Silverlight3 中 PixelFormats 和 WriteableBitmap.Lock 到哪里去了?
几个月前,我构建了一些在线示例,例如 这个来自 Jeff Prosise,它使用 Silverlight 中的 WriteableBitmap 类。
今天使用最新的 Silverlight3 安装程序 (3.0.40624.0) 重新访问它们,API 似乎发生了变化。
我弄清楚了一些变化。例如,WriteableBitmap 数组访问器已经消失,但我在新的 Pixels 属性中找到了它,因此
bmp[x]
我可以
bmp.Pixels[x]
写:这些调用是否有类似的简单替换,或者使用模式本身是否已更改?
bmp = new WriteableBitmap(width, height, PixelFormats.Bgr32);
bmp.Lock();
bmp.Unlock();
有人能给我指一个使用更新后的 API 的工作示例吗?
A few months ago I built some online samples like this one from Jeff Prosise that use the WriteableBitmap class in Silverlight.
Revisiting them today with the latest Silverlight3 installer (3.0.40624.0), the API seems to have changed.
I figured out some of the changes. For example, the WriteableBitmap array accessor has disappeared, but I found it in the new Pixels property, so instead of writing:
bmp[x]
I can write
bmp.Pixels[x]
Are there similar simple replacements for these calls, or has the use pattern itself changed?
bmp = new WriteableBitmap(width, height, PixelFormats.Bgr32);
bmp.Lock();
bmp.Unlock();
Can anybody point me to a working example using the updated API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个答案中给出了有关切换到新的 WriteableBitmap 的另一个重要细节。因为像素格式现在始终是 pbgra32,所以您必须为每个像素设置一个 alpha 值,否则您只会得到全白的图片。换句话说,以前生成如下像素值的代码
应更改为:
Another important detail about switching to the new WriteableBitmap is given in this answer ... because the pixel format is now always pbgra32, you must set an alpha value for each pixel, otherwise you just get an all-white picture. In other words, code that formerly generated pixel values like this:
should be changed to read:
如果不使用
Lock
和Unlock
而仅使用WritabelBitmap(int, int)
构造函数,会发生什么情况?东西会坏吗?在 SL3 Beta 和发行版之间,这个 API 似乎发生了变化。 查看重大更改文档勘误表(Silverlight 3)
What happens if you don't use
Lock
andUnlock
and just use theWritabelBitmap(int, int)
constructor? Do things break?It would seem that between SL3 Beta and the release this API has changed. See Breaking Changes Document Errata (Silverlight 3)