Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:11+00:00 2026-06-04T20:01:11+00:00

When my application closes, I want to serialize some data to make it persistent

  • 0

When my application closes, I want to serialize some data to make it persistent for the next use of the application. I choose to serialize these data with Newtonsoft.JsonConverter.
But, I have a BitmapImage in my class, and it can’t be serialized.

I’m bit stuck on this because I don’t find a solution to keep my BitmapImage into my class (I need to keep it here) and being able to serialize this class.
I tried to create a inherited class which contains the BitmapImage, but I’m not allowed to create an implicit operator from my base class.

I want to have an object in my class which can be used to be a source for a Image binding, and be able to serialize this class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:01:12+00:00Added an answer on June 4, 2026 at 8:01 pm

    I would suggest just “Saving the BitMap to a file” and serializing the image file name only.

    But, if you must serialize the bitmap, just save the bitmap to a MemoryStream as byte[].

    byte[] byteArray;
    
    using (MemoryStream stream = new MemoryStream()) 
    {
            Image.Save(stream, ImageFormat.Bmp);
            byteArray = stream.ToArray();
    }
    

    Update:

    Serialize your image via Image Path.

    private string m_imagePath;
    
        public Image Image { get; private set; }
    
        public string ImagePath
        {
            get { return m_imagePath; }
            set 
            {
                m_imagePath = value;
                Image = Image.FromFile(m_imagePath);
            }
        }
    

    Update:

    [JsonObject(MemberSerialization.OptIn)]
    public class MyClass
    {
        private string m_imagePath;
    
        [JsonProperty]
        public string Name { get; set; }
    
        // not serialized because mode is opt-in
        public Image Image { get; private set; }
    
        [JsonProperty]
        public string ImagePath
        {
            get { return m_imagePath; }
            set
            {
                m_imagePath = value;
                Image = Image.FromFile(m_imagePath);
            }
        }
    }
    

    As you can see, you have a json object here, that has the Opt-In attribute, meaning you need to specify which properties are serialized.
    This demo object has a Name property that is serialized, an ImagePath property that is serialized.
    However, the Image property is not serialized.
    When you deserialize the object the image will load because the ImagePath setter has the needed funcionality.

    I hope this helped, I tested it, and it works.
    Rate if you like. Good Luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this may seem like a very simple question, but I want to dump some
I am trying to call a batch file from an application, but I want
So I basically just want to know when a foreign application starts and closes.
hi I want to hook another application so when it closes I can close
I want to make the most simplest application that can communicate via windows send
I have a winform application that uses some referenced web services to get data.
The code below plots some simple x-y data, but it has two problems that
I want to make my application displayed only in portrait orientation, so I have
I am making an application that I dont want it to close. So on
I have an MFC application, which i don't want to be closed during the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.