BitmapImage Json序列化

问题描述

我如何序列化此对象。它具有BitmapImage

 enum Activity { Active,Gone,Dontdisturb }
            
        class Client : Utility.ObserableObject
        {
             string name;
             string description;
             string phone;
             Activity activity;
             string image_path;
             BitmapImage image;
                 
             public Client()
             {
                 ImagePath = "Resources\\Defaultimages\\default_user.png";
                 Activity = Activity.Active;
             }
                
             public string Name { get => name; set => Set(ref name,value); }
             public string Description { get => description; set => Set(ref description,value); }
             public string Phone { get => phone; set => Set(ref phone,value); }
             public Activity Activity { get => activity; set => Set(ref activity,value); }
             public string ImagePath { get => image_path; set => Set(ref image_path,value); }
             public BitmapImage Image { get => image; set => image = value; }
        }

在序列化此对象之前,我会从OpenFileDialog获取图像路径并将其复制到项目文件夹中

//this is a folder that is located in project     
string new_path = "Data\\Avatar\\avatar" + SelectedImage.Substring(SelectedImage.LastIndexOf('.'));

//SelectedImage is an image that user was selected from OpenFileDialog 
File.copy(SelectedImage,new_path);

Client client = new Client();
client.Name = Name;
client.Description = Description;
client.Phone = Phone;
client.ImagePath = SelectedImage;
client.Image = new BitmapImage(new Uri(Path.GetFullPath(new_path)));

string str = JsonConvert.SerializeObject(client,Newtonsoft.Json.Formatting.Indented,new
 JsonSerializerSettings()
{ TypeNameHandling = TypeNameHandling.Objects });

Console.WriteLine(client);

/////////////output of serialization////////////////////
{
    "$type": "ClientProject.Models.Client,ClientProject","Name": "Emil","Description": "Prog","Phone": "123456789","Activity": 0,"ImagePath": "Resources/Defaultimages/default_user1.png","Image": "file:///C:/Users/user/source/repos/ClientProject/ClientProject/bin/Debug/Data/Avatar/avatar.png"
}

为什么我只能看到图像路径,却看不到像大量字节那样的实际图像或类似的硫键?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)