• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

How appending 2 binary files (pictures) into another binary file

Hello,


I would like to know how I've to append 2 (or more) binary files to a third new(or already existing) binary file. (binary files = in my case pictures)

What kind of stream do I've to use (binary, memory, filestreamer, ... ?????)


If someone could send me a sample, I would really appreciate!


Thanks


Davy.


0
davyberroho
Asked:
davyberroho
1 Solution
 
TheAvengerCommented:
What's the idea? If you have 2 pictures in 1 file the will become unusable...
0
 
existenz2Commented:
You should use a bytestream to read in the pixel information, then you need to make a new picture with the approriate size and then you need to do some Maths to calculate the apprioriate pixel value for it.
0
 
davyberrohoAuthor Commented:
TheAvenger  : I just want to stock lots of images in a large file. (archiving)
0
 
gregoryyoungCommented:
           static void Main(string[] args)
            {
                  FileStream output = null;
                  FileStream input = null;
                  try
                  {
                        output = File.Open("C:\\foo.bin", FileMode.Append);
                        input = File.Open("C:\\foo2.bin", FileMode.Open);
                        int size = 2048;
                        byte [] data = new byte[size];
                        while((size = input.Read(data,0,size)) != 0)
                        {
                              output.Write(data,0,size);
                        }
                  }
                  catch (Exception Ex)
                  {
                        throw new System.Exception("Unable to append data", Ex);
                  }
                  finally
                  {
                        if(output != null)
                        {
                              output.Close();
                        }
                        if(input != null)
                        {
                              input.Close();
                        }
                  }
            }



just keep in mind that you would need to maintain indexes to where the files are in the big file.

Greg

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now