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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:06:19+00:00 2026-05-12T07:06:19+00:00

I am working on constructing and saving a bitmap, and i have a loop

  • 0

I am working on constructing and saving a bitmap, and i have a loop that sets the pixels in the bitmap to their proper values. However it crashes after a short period of ime with an IndexOutOfRange exception at the noted point in the code.

    //data is an array of bytes of size (image width * image height) * 2;
    Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb);
    for (int i = 0; i < data.Length; i += 2)
    {
        int luminance = ((int)data[i] << 8) | (int)data[i + 1];
        Color c = Color.FromArgb(luminance,luminance,luminance,luminance);

        int x = i / 2;
        int y = x / width;
        x %= width;
        b.SetPixel(x, y, c);//crashes here when Y is at 513, should only go to 512
    }
    b.Save(Path.GetFileNameWithoutExtension(fileName) + ".bmp");

I’m stumped as to why this happens.Why does this happen and how can i fix it?

(a note ot all of those that reommend unsafe code: I am going for a working program then a fast one. I’ll be sure to write up 3 questions on the subject when i start! 😉 )

  • 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-12T07:06:19+00:00Added an answer on May 12, 2026 at 7:06 am

    It’s hard to tell what might be wrong without knowing what your data actually is. I suspect that it might be organised into rows like a bitmap, but sometimes bitmap format data requires that rows be a multiple of 4 bytes in length (with unused padding at the end, see BMP file format). If this is the case, your y value might become larger than you expect. You may need to take such padding into account.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You may want to try this method: - (void)setTextSizeMultiplier:(float)multiplier. May 12, 2026 at 7:25 pm
  • Editorial Team
    Editorial Team added an answer You have a setPriority() method in the Thread class. Check… May 12, 2026 at 7:25 pm
  • Editorial Team
    Editorial Team added an answer I think you want: object tmp = Activator.CreateInstance(SelectedItem.UserControlType); If that's… May 12, 2026 at 7:25 pm

Related Questions

I've been tasked with the the maintenance of a nonprofit website that recently fell
A project I'm working on at the moment involves refactoring a C# Com Object
I have recently started looking into Google Charts API for possible use within the
I'm working on a Wake on LAN service that will run from a web

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.