1

I have a BitmapImage and I need to store the content of this image (as byte array for example) in a text file.

In particular, I have to store this image in the attribute of an XML node, and then I have to read this node to create a new BitmapImage.

What is the fastest way to do this?

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
gliderkite
  • 8,828
  • 6
  • 44
  • 80

1 Answers1

4

Use Convert's ToBase64String to covert Bytes to readable ASCII characters

string bitmapImageAsString=Convert.ToBase64String(binaryData);

You can convert that string back using Convert.FromBase64String


To convert BitmapImage to byte array refer this..

Though you can also use BitmapImage.StreamSource to identify the source stream and then convert that stream to byte array..That would be a better option

Community
  • 1
  • 1
Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • To convert my `StreamSource` to a byte array I'm using [this](http://stackoverflow.com/a/7073124/995246) method. But I think it's a huge waste of resources... Do you know a better way? – gliderkite Oct 19 '13 at 07:14
  • @gliderkite performance won't be a problem here but if you want your code to copy that stream without **blocking** you can use [CopyToAsync](http://msdn.microsoft.com/en-us/library/hh159084.aspx) – Anirudha Oct 19 '13 at 07:39