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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:18:07+00:00 2026-05-13T10:18:07+00:00

I have a problem to convert an byte array to double array using BitConverter.ToDouble()

  • 0

I have a problem to convert an byte array to double array using BitConverter.ToDouble().

Simply my program will select an image then convert the image to byte array.
Then it will convert the byte array to double array.

The problem that when I convert the byte array to the double I will get this error before the loop finish.

(Destination array is not long enough to copy all the items in the collection. Check array index and length.)

The error happen exactly at array.Length-7 position which is last seventh position before the last position on the array.

I need help to solve this problem and here is my code:

private Bitmap loadPic;
byte[] imageArray;
double[] dImageArray;

private void btnLoad_Click(object sender, EventArgs e)
{
    try
    {
        OpenFileDialog open = new OpenFileDialog();
        open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

        if (open.ShowDialog() == DialogResult.OK)
        {
            pictureBox1.Image = new Bitmap(open.FileName);
            loadPic = new Bitmap(pictureBox1.Image);
        }
    }
    catch
    {
        throw new ApplicationException("Failed loading image");
    }

    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}

private void btnConvert_Click(object sender, EventArgs e)
{
    imageArray =  imageToByteArray(loadPic);
    int index = imageArray.Length;
    dImageArray = new double[index];

    for (int i = 0; i < index; i++)
    {
        dImageArray[i] = BitConverter.ToDouble(imageArray,i);
    }
}   

public byte[] imageToByteArray(Image imageIn)
{
    MemoryStream ms = new MemoryStream();
    imageIn.Save(ms, ImageFormat.Gif);
    return ms.ToArray();
}
  • 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-13T10:18:07+00:00Added an answer on May 13, 2026 at 10:18 am
    BitConverter.ToDouble(byte[], int)
    

    uses eight bytes to construct a 64-bit double, which explains your problem (once you get to the 7th to last element, there are no longer eight bytes left). I’m guessing this is not what you want to do, based on how you set up your loop.

    I imagine you want something like:

    for(int i = 0; i < index; i++)
    {
        dImageArray[i] = (double)imageArray[i];
    }
    

    Edit – or using LINQ, just for fun:

    double[] dImageArray = imageArray.Select(i => (double)i).ToArray();
    

    On the other hand…

    If BitConverter is definitely what you want, then you’ll need something like:

    double[] dImageArray = new double[imageArray.Length / 8];
    for (int i = 0; i < dImageArray.Length; i++)
    {
        dImageArray[i] = BitConverter.ToDouble(imageArray, i * 8);
    }
    

    Again, based on your code, I think the first solution is what you need.

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

Sidebar

Ask A Question

Stats

  • Questions 278k
  • Answers 278k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Maybe using a Proxy? The Proxy class lets you override… May 13, 2026 at 3:11 pm
  • Editorial Team
    Editorial Team added an answer might wanna keep the path the CFC not part of… May 13, 2026 at 3:11 pm
  • Editorial Team
    Editorial Team added an answer Just assign it to the field. public class Packet {… May 13, 2026 at 3:11 pm

Related Questions

I have binary data in a file that I can read into a byte
This is a long one du to config files... I'm running a upgrade from
I don't know a better title, but I'll describe the problem. A piece of
This is my 3rd thread concerning a blowfish problem in C#.Despite the fact I
I have an array of different type objects and I use a BinaryWriter to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.