开发者

Image url to byte array using Silverlight

How to convert image url to byte array or stream using Silverlight开发者_JAVA百科?


Easiest thing to do is use WebClient to download the Uri as a Stream. For this to work at least one of the following must be true:

  1. The image is hosted on the same domain as the Silverlight app.
  2. The domain that the image is hosted on is providing a clientaccesspolicy file to allow your Silverlight app to access the image.

This will give you access to the contents of the file as a Stream. If you want access to the decoded pixels rather than the raw contents of the file, load the Stream into an Image element (using BitmapSource.SetSource(Stream)), wait for the Image.ImageOpened event and then capture the Image element in a WriteableBitmap. You can then read the image pixel data from the WriteableBitmap.Pixels array. If the image is not coming cross-domain, you do not need to download the Stream and can just set the Image Source to the URI directly,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜