WriteableBitmap 在 Silverlight 4 中有新功能吗?
如果有人能给我一个关于如何使用它的例子,通过流? (不确定它是如何工作的)我知道如何从 URI
创建 BitmapImage
现在我需要将此图像转换为 WriteableBitmap
,但是我收到一个空异常错误,如下所示:
BitmapImage image = new BitmapImage(new Uri("http://www.example.com/example.png"));
WriteableBitmap newImage = new WriteableBitmap(image);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之:不,Silverlight 4 中没有新功能。 WriteableBitmapEx 尝试弥补缺失的功能。
关于您的实际问题:
您应该将处理程序添加到 BitmapImage.ImageFailed 事件以查看下载图像时是否出现错误。您应该在 ImageOpened 事件处理程序。
另请注意,允许跨域引用。有关详细信息,请参阅 MSDN 页面。 您应该将图像放入 Web 项目的 ClientBin 文件夹中并使用相对路径。
作为替代方案,您还可以将图像作为资源编译到程序集中并从那里加载。 WriteableBitmapEx 有一个扩展方法可以使此任务变得更容易一些。但请记住,这会增大程序集大小,并且初始 XAP 加载时间也会增加。
In short: Nope, there are no new features in Silverlight 4. The WriteableBitmapEx tries to compensate the missing functionality.
Regarding your real problem:
You should add a handler to the BitmapImage.ImageFailed event to see if there's an error when the image should be downloaded. And you you should create the WriteableBitmap in the ImageOpened event handler.
Please also note that cross-domain references are permitted. See the MSDN page for details. You should put the image into the Web Project's ClientBin folder and use a relative path instead.
As an alternative you can also compile the image into the assembly as resource and load it from there. The WriteableBitmapEx has an extension method to make this task a bit easier. But keep in mind that this blows the assembly size up and the initial XAP loading time will increase.