This question is specific to Windows Store App (Windows 8).
I'm trying to convert a Bitmapimage
to Byte[]
and store it in a xml file, then retrieve and convert it back to Bitmapimage
.
I was able to convert the Bitmapimage
to byte[]
(although it's not the best way, so I'm not including example). Then I'm using serialization to convert a class to xml. Here's the attribute used to serialize byte[]
:
private byte[] iconBytes;
[XmlAttribute(DataType = "base64Binary")]
public byte[] IconBytes
{
get
{
// TO DO: Convert BitmapImage to Byte[]
return this.iconBytes;
}
set
{
this.SetProperty(ref this.iconBytes, value);
// TO DO: Convert Byte[] to BitmapImage
}
}
And here is the XML generated:
<MyApp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Groups>
<Group Title="Group1">
<Items>
<Item Title="Item1" IconBytes="7uLC/+7iwv/u4sL/7uLC/0RVZf9heJL/X3OH/+vbvP/r27b/69u2/+vbtv/r27b/7d+9/+3fvf/r27z/R2aO/2Z2t/92h9T/obH3/3uXxP/lz57/5c+e/+XPnv/lz57/6dW3/+nVt//azbf/Um6o/2Jqu/9ib77/lqbp/4uq5//gw5T/4MOU/+DDlP/iyJj/5tCy/97Akf/Mt5b/Ulh+/ygpZv82P47/HhpG/01rpv+Npqn/3LuM/9y7jP/ewJH/27KF/9uyhf+xrKf/VWet/1hatf9reND/UVzD/5Sp8f+qmoL/27KF/9uyhf/ft5H/1q2A/9atgP/WrYD/QU6Y/zY2eP8wKFf/cHit/1ZtsP/WrYD/1q2A/9atgP/bsoX/0KF1/9Chdf/QoXX/NkqC/z5Bh/9KRaH/X3W4/zRMf//QoXX/0KF1/9Chdf/UqXz/zZlv/82Zb/8yJCD/Nj5u/0FOkP9FS5j/Wm+2/09rov9CMTP/zZlv/82Zb//QoXX/KBkV/yUWE/8eEg3/rKCc/ycmUP8yOnL/PU6E/2Nfdf9CLSj/LR0Y/zwnIf9fUUT/IxMQ/yASDP8dDwz/dWpp/4eGiP82QHT/QT5h/4l2c/80IB3/NCAc/yoZFf81IR//IBQO/x0QDP8dDgv/HQ4L/5eTkf+OmKL/k5KT/zAeG/8tHhf/KRsU/zIfGv8tHhf/IREN/x8PC/8fEAz/HhEM/7Suq/+dnaL/qqek/zAeGv8hFA//KBkU/ygaFP8uGhb/" />
</Items>
</Group>
</Groups>
</MyApp>
Once I deserialize the class from the xml, how can I convert byte[]
to BitmapImage
?
There are several examples out there addressing this issue, but they are all related to Silverlight and WPF, and none of them translate successfully to Windows Store App (Windows 8).
Please keep in mind that examples using streams from the web or local computer does not apply to this issue. The image byte[]
is already in memory because the data was deserialized from an xml file.
Any help is greatly appreciated. Happy New Year!