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 8224857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:12:59+00:00 2026-06-07T15:12:59+00:00

I have binary files which contain each one PNG file at a time (the

  • 0

I have binary files which contain each one PNG file at a time (the binary file is not a DLL, not a EXE, nothing usual, just a file which contains different textual information, a PNG file and some other stuff. The format of the file is unknown to me. The PNG file is displayable with a program which does this kind of files). I have not the source of this program which does these files.
My task is now to extract this PNG file out of the binary file for displaying it or saving it as PNG. I wrote a code which works on some of these files (let’s say about 50% of the files), but on anothers not. On the not working files the program which created this files can still display the containing image, so the image is inside of every file surely valid – but anyway my code doesn’t work on some of the files.

Some images seem to have maybe another format, maybe encoding type (I tried already all different encoding types, nothing succeeded). Here is my code (I hope someone can tell me what to change that the image becomes readable always).

What does my code: It finds the know starting string of the PNG image “‰PNG” and the known ending string “IEND®B`‚”. This strings are in any of my binary files containing the PNG’s the same.
Then my code takes the string between start and end + the start and the end sequence and saves it
to a file with Encoding.Default. Most by this way extracted PNG files can be displayed with an Image Viewer, but around 50% are invalid. The image looks okay if I open it with an editor and compare the characters to a working image. Sofar I have no clue which symbol is the reason for the wrong image format.

If needs I’ll provide more information, here my code:

private void button2_Click(object sender, EventArgs e)
    {
        string ReadFile1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "file.dat");
        string WriteFile1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "test.png");
        string TMP = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), ReadFile1), Encoding.Default); //System.Text.Encoding.GetEncoding(1251)
        int start1 = TMP.IndexOf("PNG", 0 ,StringComparison.Ordinal);
        if (start1 == 0) { return; }
        int end1 = TMP.IndexOf("IEND", StringComparison.Ordinal);
        string PNG = TMP.Substring(start1 - 1, (end1 + 9) - start1);
        File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "test.png"), PNG, Encoding.Default);
    }

I also thought first of getting the PNG with a binary method and used this code,
but I had exactly the same results then with just reading the string. Here my earlier
code. I seeked the position in the byte array using the string to compare.
I had no luck with the binary code…

 byte[] by;
        // 1.
        // Open file with a BinaryReader.
        using (BinaryReader b = new BinaryReader(File.Open(ReadFile1, FileMode.Open), Encoding.Default))
        {
            // 2.
            // Variables for our position.
            int pos = start1 - 1;           //I determine the right positions before doing this
            int required = (end1 + 9) - start1; 

            // 3.
            // Seek to our required position.
            b.BaseStream.Seek(pos, SeekOrigin.Begin);

            // 4.
            // Read the next 2000 bytes.
            by = b.ReadBytes(required);
            b.Close();
        }

        FileStream writeStream;
        writeStream = new FileStream(WriteFile1, FileMode.Create);
        BinaryWriter writeBinay = new BinaryWriter(writeStream, Encoding.Default);
        writeBinay.Write(by);
        writeBinay.Close(); */
  • 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-07T15:13:01+00:00Added an answer on June 7, 2026 at 3:13 pm

    PNG files are binary. If you read them using some encoding, you’ll loose information and the output of your program is not a valid PNG file any more. Refer to Using Chunks in a PNG for more explanation and code samples.

    Also read PNG Specifiaction: File structure for detailed information.

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

Sidebar

Related Questions

I have a bunch of files which contain an ascii header with a time
I have a set of zip files which contains several ieee-be encoded binary and
I have a binary file, that was written in C, which contains a long
i have a binary file which has 4 KB of header information and then
I have a binary file to which I want to append a chunk of
I have a binary file to which I'm trying to write however I dont
We have a binary file from which we have identified the following dates (as
I have a large binary file (700 Mb approximately) which I load to TMemoryStream.
I have written a raw binary image file into a buffer which is an
I have an ASP.net application which returns a binary PDF file (stored from 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.