Serializing a BitmapImage in WinRT

后端 未结 1 1380
灰色年华
灰色年华 2021-01-28 14:36
public static async Task SaveFileAsync(string FileName, T data)
{
    MemoryStream memStream = new MemoryStream();
    DataContractSerializer serializer = new DataContra         


        
相关标签:
1条回答
  • 2021-01-28 15:18

    DataContractSerializer won't work with images. You should either use BitmapEncoder (if you are dealing with WriteableBitmap or simply serialize the source address of your BitmapImage. If the bitmap was loaded from a local path or a temporary URL and you want to persist the entire bitmap - you can't extract the bitmap bits from BitmapImage anyway and so you need to either download the source file from the original source URL or copy the local file you loaded. You could then either save that copy as a loose file or serialize as say Base64 inside of your DataContractSerializer-created XML.

    0 讨论(0)
提交回复
热议问题