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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:19:21+00:00 2026-05-13T08:19:21+00:00

I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap

  • 0

I have some code that does something like this (Irrelevant bits snipped):

void foo(Bitmap bmp1, Bitmap bmp2)
{
    Bitmap bmp3;
    if(something)
        bmp3 = new Bitmap(bmp1.Width, bmp1.Height + bmp2.Height);
    else
        bmp3 = new Bitmap(bmp1.Width, 18000);
    (more stuff here that runs fine)
}

Anywho most of the time this ran fine. At first. As the project continued it started to fail on the new Bitmap line. The error it gives is: “ArgumentException was unhandled. Parameter is not valid.” There’s no mention of which parameter it has a problem with or anything. I’m stumped. Here’s what I know for sure:

  1. bmp1 and bmp2 have never been null
    when this error is thrown.
  2. The if statement’s presence has
    never made a difference; it dies
    just as frequently without.
  3. Both examples of the constructor use
    have thrown this error.

I’m tempted to say this is a memory error, except it doesn’t mention anything of the sort. The first dozen times or so this happened the heights totalled over 18000 (hence the magic number above). Figuring it was some kind of soft barrier to our system, we just limited the images at that height which made the exceptions go away after a while.

For some sample data, the exception I’m looking at right now has bmp1.Width at 2550, bmp1.Height at 6135 and bmp2.Height at 6285.

Anyone have any ideas?

  • 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-13T08:19:21+00:00Added an answer on May 13, 2026 at 8:19 am

    GDI+ does not generate very good exception messages. The exception you got is flaky, this one will generate it reliably on my machine:

        private void button1_Click(object sender, EventArgs e) {
            var bmp = new Bitmap(20000, 20000);
        }
    

    What’s really going on is that this bitmap requires too much contiguous unmanaged memory to store the bitmap bits, more than is available in your process. On a 32-bit operating system, you can only ever hope to allocate a chunk of memory around 550 megabytes. That goes quickly down-hill from there.

    The issue is address space fragmentation, the virtual memory of your program stores a mix of code and data at various addresses. Total memory space is around 2 gigabytes but the biggest hole is much smaller than that. You can only consume all memory with lots of small allocations, big ones fail much quicker.

    Long story short: it is trying to tell you that the size you requested cannot be supported.

    A 64-bit operating system doesn’t have this problem. Be sure to take advantage of it with Project > Properties > Build tab, Platform target = AnyCPU and Prefer 32-bit = unticked. Also, WPF relies on WIC, an imaging library that’s a lot smarter about allocating buffers for bitmaps.

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

Sidebar

Ask A Question

Stats

  • Questions 386k
  • Answers 386k
  • 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 Capybara uses xpath by default, so unless you changed that… May 14, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer You can use array_filter() to get back a new array… May 14, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Yes, this is possible with Ajax. It's easiest, frankly, if… May 14, 2026 at 11:45 pm

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.