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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:38:20+00:00 2026-05-26T13:38:20+00:00

I’m trying to draw a bmp image file from a 2 dimensional Boolean array.

  • 0

I’m trying to draw a bmp image file from a 2 dimensional Boolean array. The objective is the following i need to draw a small square for each value and the color depends on the boolean if true it paints in a given color and if false it paints white.
the idea is to create a maze based on the matrix

Most solutions i find over the web are with 1 dimensional byte array using MemoryStream but i doesn’t paint a full square with a size of my choosing.

My main problem is how to draw on a bmp or an image using c#

thanks in advance for any advice

  • 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-26T13:38:20+00:00Added an answer on May 26, 2026 at 1:38 pm

    Here’s a solution that uses a 2 dimension array and saves the resulting bitmap. You’ll have to either read in the maze from a text file or hand enter it as I have done. You can adjust the size of the tiles with the squareWidth, squareHeight variables. Using a one-dimensional array would also work, but may not be as intuitive if you’re just learning about these things.

    bool[,] maze = new bool[2,2];
    maze[0, 0] = true;
    maze[0, 1] = false;
    maze[1, 0] = false;
    maze[1, 1] = true;
    const int squareWidth = 25;
    const int squareHeight = 25;
    using (Bitmap bmp = new Bitmap((maze.GetUpperBound(0) + 1) * squareWidth, (maze.GetUpperBound(1) + 1) * squareHeight))
    {
        using (Graphics gfx = Graphics.FromImage(bmp))
        {
            gfx.Clear(Color.Black);
            for (int y = 0; y <= maze.GetUpperBound(1); y++)
            {
                for (int x = 0; x <= maze.GetUpperBound(0); x++)
                {
                    if (maze[x, y])
                        gfx.FillRectangle(Brushes.White, new Rectangle(x * squareWidth, y * squareHeight, squareWidth, squareHeight));
                    else
                        gfx.FillRectangle(Brushes.Black, new Rectangle(x * squareWidth, y * squareHeight, squareWidth, squareHeight));
                }
            }
        }
        bmp.Save(@"c:\maze.bmp");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from

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.