Recently, I came across a interesting question on how to convert from a byte array to BitmapImage. The typicall scenario is when given an image represented by BitmapImage object it should be stored in a database as byte.
The code I’m going to show below has been extracted from Stackoverflow.com but I found it in several sites after googling, therefore I can’t point out the author.
The code is quite simple just use:
Where ToByteArray method is:
Another way to achieve it is using ImageTools for Silverlight. I have used it in several Windows Phone projects, specially animating gif images, and it contains a method that could be used in order to convert BitmapImage from and to byte by just using a few lines of code:
Both solutions works fine. The first one does not need any kind of library reference meanwhile the second one needs ImageTools library (that could be reached in Nuget).