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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:14:10+00:00 2026-06-14T05:14:10+00:00

My friends send me a file. He save multiple gif file in one file

  • 0

My friends send me a file. He save multiple gif file in one file and he give me list like

file1 - StartFrom - 1 and length 18493,
file2 - StartFrom - 132089 and length 824,
file3 - StartFrom - 18494 and length 2476 etc..

I don’t know how he put all gif file into one file. I need extract all gif image from this file.

Is anyone help me one how i write a code in vb.net or C# . I write a code below:

private void button1_Click(object sender, EventArgs e)
{

    byte[] buffer = new byte[18493];


    string destPath = Application.StartupPath + "\\mm.gif";
    string sourcePath = Application.StartupPath + "\\Data.qdd";

    var destStream = new FileStream(destPath, FileMode.Create);

    int read;
    var sourceStream = new FileStream(sourcePath, FileMode.Open);
    while ((read = sourceStream.Read(buffer, 1, 18493)) != 0)
          destStream.Write(buffer, 0, read);

}

But there is and error show is :

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

  • 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-14T05:14:11+00:00Added an answer on June 14, 2026 at 5:14 am

    EDIT edited solution

    The error lies here

    read = sourceStream.Read(buffer, 1, 18493)
    

    You create a buffer byte array variable with length 18493, so it has 18493 elements.
    The position in the array are from 0 to 18492.
    The Read function try to write 18943 byte from position 1, so the last byte will be written to buffer[18943] going out of the limit of your array.
    Try to change the read to

    read = sourceStream.Read(buffer, 0, 18493)
    

    EDIT 2 Solution to the whole problem

    To solve the problem and not just the error you should allocate three different buffer and write free different file. (You could use just one buffer and clean it every time, but is easier to understand if you use three of them)
    You cannot use a while to read because in that way you’ll go to the end of the file!
    Just read the file for the desired lenght and then move for the next file.

    private void button1_Click(object sender, EventArgs e)
    {
    
        byte[] buffer1 = new byte[18493];
        byte[] buffer2 = new byte[824];
        byte[] buffer3 = new byte[2476];
    
    
        string destPath1 = Application.StartupPath + "\\mm1.gif";
        string destPath2 = Application.StartupPath + "\\mm2.gif";
        string destPath3 = Application.StartupPath + "\\mm3.gif";
        string sourcePath = Application.StartupPath + "\\Data.qdd";
    
        var destStream1 = new FileStream(destPath1, FileMode.Create);
        var destStream2 = new FileStream(destPath2, FileMode.Create);
        var destStream3 = new FileStream(destPath3, FileMode.Create);
    
        int read;
        var sourceStream = new FileStream(sourcePath, FileMode.Open);
        if ((read = sourceStream.Read(buffer1, 0, 18493)) != 0)
              destStream1.Write(buffer1, 0, read);
        //file three is the next in the stream
        if ((read = sourceStream.Read(buffer3, 0, 2476)) != 0)
              destStream3.Write(buffer3, 0, read);
        //there some unused space, move to the start of the second gif file
        sourceStream.Seek(132089, SeekOrigin.Begin);
        if ((read = sourceStream.Read(buffer2, 0, 824)) != 0)
              destStream2.Write(buffer2, 0, read);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear friends, I need your help. I need to send .bmp file to another
I am trying to send app request notification to multiple friends using Graph api,,here
I like to write a Java application which I will give to my friends
I can send requests to friends using Multi Friend Request Selector inside my Page
I want to send message/notification to friends with customized subject with a link in
I am trying to send mail to my friends through my Java Mail application.
I often want to send sample apps to friends & colleages that work with
I would like to send a sound over my input device: I don't want
Friends, i have a xml file including a Sliding drawer. I setContentView in the
in my iPhone App i am trying to send data from one device to

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.