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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:59:54+00:00 2026-05-28T06:59:54+00:00

I working on a maze generator in C# which generates big mazes and then

  • 0

I working on a maze generator in C# which generates big mazes and then saves them to a png file.

Currently I’m running against some errors when I’m trying to save the image.

When I use this:

System.Drawing.Bitmap tempBitmap = new System.Drawing.Bitmap(16000, 16000);

I get an argument exception. (It does work with 8000*8000)

When I use the WPF way of doing it:

RenderTargetBitmap rtb = 
              new RenderTargetBitmap(16000, 16000, 96, 96, PixelFormats.Pbgra32);

I get a memory overflow exception.

Does anyone have another way to save big images in c#?

I’ve looked at some libraries too without success.

Someone also said that I should first save the image in parts and then combine them, but how can I do this?

Edit:

Edit2:
I’m now trying PixelFormat.Format1bppIndexed like this:

private Bitmap CreateBitmapImage2(BitArray[] map, List<Point> path)
{
    Bitmap objBmpImage = new Bitmap(cursize * (map[0].Length - 1), cursize * (map.Length - 1), PixelFormat.Format1bppIndexed);

    Rectangle rect = new Rectangle(0, 0, objBmpImage.Width, objBmpImage.Height);
    System.Drawing.Imaging.BitmapData bmpData =
        objBmpImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
        objBmpImage.PixelFormat);

    IntPtr ptr = bmpData.Scan0;

    int bytes = Math.Abs(bmpData.Stride) * objBmpImage.Height;
    byte[] rgbValues = new byte[bytes];

    System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

    int counter = 0;
    int counterdeluxe = 0;
    BitArray bitarray = new BitArray(8);

    Random r = new Random();

    Boolean last = true;
    for (int i = 0; i < 225 / 8; i++)
    {
        rgbValues[i] = (byte)r.Next(255);
    }

    System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);


    objBmpImage.UnlockBits(bmpData);

    return (objBmpImage);
}

Though for some reason it only creates half an image:
http://dl.dropbox.com/u/1814002/maze.png

Edit4:
Ah it seems that the bits in the width are always rounded up to a 4 byte number. Now it starts to make sense to me :).

Edit5:
Ok it doesn’t make sense anymore lol, I’ll just stay with the graphics for now I guess

Edit6:
I couldn’t let it go so I looked at it again and found out the following:
At the point where I use a BitArray to convert my seperate bits to a byte which I then write to the ImageData something was going wrong, apparently the bitarray had to be written to in reverse. Finally everything works correctly now :).

All problems solved and my maze generator is up and running. Thanks everyone 🙂

  • 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-28T06:59:55+00:00Added an answer on May 28, 2026 at 6:59 am

    If your mazes are just black/white, you might want to try:

    Bitmap bitmap = new Bitmap(16000, 16000, PixelFormat.Format1bppIndexed);
    

    Assuming it keeps the image in that format in memory, that should be considerably more efficient than the default pixel format.

    On my box (which has 12GB of memory, admittedly), 16000×16000 works by default, but 32000×32000 doesn’t. Even 32000×32000 works with Format1bppIndexed though.

    EDIT: As noted in comments, you should use using statements for bitmaps:

    using (Bitmap bitmap = ...)
    {
    }
    

    … so that they can be cleaned up appropriately.

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

Sidebar

Related Questions

I've written some code that generates mazes for me. The maze consists of (n
Working on a project that parses a log of events, and then updates a
Working with python interactively, it's sometimes necessary to display a result which is some
Working on writing a custom property Handler for our custom file type in windows
I'm working on a simple multiplayer game in which 2-4 players are placed at
I am working on the project of marble maze game in j2me.I am facing
I am working on a project where I need to solve a maze using
I'm working on an iPhone game with a bunch of mazes, and there's this
I'm still working on my Cell class for my maze game I'm attempting to
I'm trying to create a random maze generator in javascript. There may already be

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.