merge multiple JPEG file into one file

Posted on 2004-11-20
Last Modified: 2011-09-20
anyone know how to merge JPEG file into one file?

example :
i want to create software that can merge 5 JPEG file into one file.
this one file can be opened but only with my software.
so in my software i can look this images but at different page
i mean i can see 1.jpg then 2.jpg then 3.jpg

please tell me the solution...

i don't need the program but i need "How to"

Question by:rusdyrip
    LVL 6

    Accepted Solution

    i dont believe that the jepg format supports multipage - tiff does and you can murge multipil jegs into a tiff.
    It sounds like you want to make you own img format that only your software can read. is this correct?

    here is the route I would take:

    create a random access datafile - this way you keep the original jpeg files intack incase you need them later.

    create a type that has the image data and possibly some extra info about the image
    output all 3 types to the .xxx file

    then you can use a simple vb image control to display the images.
    LVL 28

    Expert Comment

    Not sure if this will help,but check out this example:
    LVL 28

    Assisted Solution

    Not sure if this will help,but check out this example:
    LVL 7

    Expert Comment


    Just a quick note of consideration.  To solve this problem you have one issue you have to get around.  That issue is how you are going to convert/revert a .JPG or picture into an array of BYTE.  Once you do this then it is easy enough to write/read the byte array to/from a binary file.

    The problem is that there is no easy way to do this in VB other than one that I am not personally satisfied with.  As a result most sample code you see on the web for this type of problem will use this simple approuch.  Basically it goes like this.

    Write the JPG to a temporary file.
    Read that temporary file into a BYTE array.
    Throw the BYTE array into a DB or in your case append it to you combined file.

    In the code sample given by vinnyd79 this is basically what is happening; although, in its case it doesn't need the first step since it is asking the user for a path to an existing .JPG file.  That first step is only important for code that needs to manage pictures that do not already exist in files.

    Now, there are harder ways to get around all of this using API calls or easy but costly ways of buying a third party image control that will give you access to the Binary image data or long runtime methods of quarying each pixel and generating the BYTE array directly from the picture control; however, if the above method does not bother you then that is probably the quickest/easiest approuch.
    LVL 2

    Assisted Solution

    what you could do is making a completely binary file, but you need to make it idiot secure or murphies law will haunt you.
    what you need is the lengths of the files, eg:

    file1.jpg = 1000bytes
    file2.jpg = 1500bytes
    file3.jpg = 500bytes

    file lengths can be obtained with FileLen() function

    then you need to open the files you want to merge 1 by 1 while having an output file ready. put in the length of the input file, and then get the data from the first file and put down the other, eg:

    Open output file (For Binary)

    Write size of the input file1 as a long to the output file
    Open input file1 (For Binary)
    Copy the contents of input file1 to output file
    Close input file1

    Write size of the input file2 as a long to the output file
    Open input file2 (For Binary)
    Copy the contents of input file2 to output file
    Close input file2

    Write size of the input file3 as a long to the output file
    Open input file3 (For Binary)
    Copy the contents of input file3 to output file
    Close input file3

    Close output file

    now this is a very primitive way of merging.
    to read you simply read the size of a long, and then read the number as many bytes as the long says. so if the long says 1000 then you read 1000 bytes and put into a normal jpg file and load it with LoadPicture()

    now to extract files youll have reverse this by reading a long (4 bytes) and then copying as many bytes out of the file as the long indicates, eg:

    Open input file (For Binary)

    Open output file1 (For Binary)
    Read the size indicator (long, 4 bytes)
    copy <long> bytes out of the file and into output file1
    Close output file1


    Close input file

    then you can use loadpicture to load the jpg as normally. when its loaded i think you can actually delete the file and have the file only in your picturebox.

    I hope this answers your question
    /Z out

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now