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:
- The image is hosted on the same domain as the Silverlight app.
- 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,
精彩评论