BitmapImage Json序列化
如何序列化此对象。它有位图图像BitmapImage Json序列化,json,bitmapimage,Json,Bitmapimage,如何序列化此对象。它有位图图像 enum Activity { Active, Gone, DontDisturb } class Client : Utility.ObserableObject { string name; string description; string phone; Activity activity;
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"
}
为什么我只看到图像路径,而不是像大量字节之类的实际图像