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

  • SEARCH
  • Home
  • 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 3270592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:39:15+00:00 2026-05-17T18:39:15+00:00

I have a byte[] that was serialized with the following code: // Save an

  • 0

I have a byte[] that was serialized with the following code:

// Save an object out to the disk
public static void SerializeObject<T>(this T toSerialize, String filename)
{
    XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
    TextWriter textWriter = new StreamWriter(filename);

    xmlSerializer.Serialize(textWriter, toSerialize);
    textWriter.Close();
}

problem is the data serialized looks like this:

iVBORw0KGgoAAAANSUhEUgAAAPAAAAFACAIAAAANimYEAAAAAXNSR0IArs4c6QAAAARnQU1BAACx......

when it gets stored in my database it looks like this:

0x89504E470D0A1A0A0000000D49484452000000F00000014008020000000D8A660400000001......

What is the difference, and how can I get the data from the disk back into a byte[]?


Note: the data is a Bitmap formatted as a png like this:

public byte[] ImageAsBytes
{
    get
    {
        if (_image != null)
        {
            MemoryStream stream = new MemoryStream();
            _image .Save(stream, ImageFormat.Png);
            return stream.ToArray();
        }
        else
        {
            return null;
        }
    }
    set
    {

        MemoryStream stream = new MemoryStream(value);
        _image = new Bitmap(stream);
    }
 }
  • 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-05-17T18:39:15+00:00Added an answer on May 17, 2026 at 6:39 pm
    iVBORw0KGgoAAAANSUhEUgAAAPAAAAFACAIAAAANimYEAAAAA...
    

    is base64 encoded representation of the binary data.

    0x89504E470D0A1A0A0000000D49484452000000F000000140080...
    

    is hexadecimal.

    To get the data back from the disk use XmlSerializer and deserialize it back to the original object:

    public static T DeserializeObject<T>(string filename)
    {
        var serializer = new XmlSerializer(typeof(T));
        using (var reader = XmlReader.Create(filename))
        {
            return (T)serializer.Deserialize(reader);
        }
    }
    

    But if you only have the base64 string representation you could use the FromBase64String method:

    byte[] buffer = Convert.FromBase64String("iVBORw0KGgoAAANimYEAAAAA...");
    

    Remark: make sure you always dispose disposable resources such as streams and text readers and writers. This doesn’t seem to be the case in your SerializeObject<T> method nor in the getter and setter of the ImageAsBytes property.

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

Sidebar

Related Questions

We have a production system that uses a lot of Serialization. What be basically
I am looking for a way to add a serialized value of an object
I am attempting to make a simple class that serializes itself to disk when
I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto
I have a byte[]. It contains data of an image (jpeg or bitmap) with
I have six boolean flags that are independent of each other so there are
I have two byte[] and I want to find the first occurrence of the
I have an array of bytes that is referenced in some high-level client/developer documentation
I'm trying to serialize a class in which I have a bitmap variable. Here
Anytime I try to serialize a file I get the error: FileNotFound. Not sure

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.