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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:10:34+00:00 2026-06-12T07:10:34+00:00

Okay so I’m making a spritesheet maker at the moment and I have hit

  • 0

Okay so I’m making a spritesheet maker at the moment and I have hit a little snag.
I have made the code and it successfully pulls all the images into the memory stream and places them together, but when it comes to saving the program returns a Generic GDI+ error.
I have tried opening another memory stream to save the new bitmap under but it turns out I cannot create a Memory Stream of a virtual file.
Anyway here’s the code so far:

class SpriteMaker
{
    static void Main()
    {
        bool cont = false;
        bool skip = false;
        while (cont == false)
        {
            Console.WriteLine("Enter a Folder name(end to end):");
            string fold = Console.ReadLine();
            if (fold.Equals("end"))
            {
                break;
            }
            try
            {
                string[] files = Directory.GetFiles(@"sprites\" + fold, "*.PNG");
                foreach (string file in files)
                {
                    Console.WriteLine(file);
                }
                skip = false;
            }
            catch (Exception)
            {
                Console.WriteLine("Folder not Found!");
                Console.WriteLine("Try Again!");
                cont = false;
                skip = true;
            }
            if (skip != true)
            {
                try
                {
                    string[] files = Directory.GetFiles(@"sprites\" + fold, "*.PNG");
                    System.Drawing.Bitmap stitchedImage = Combine(files);
                    Console.WriteLine("save filename (no extention)");
                    string fil = Console.ReadLine();
                    stitchedImage.Save(@"/sheets/"+fil+".png", System.Drawing.Imaging.ImageFormat.Png);
                    cont = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error Creating Sprite Sheet");
                    Console.WriteLine(ex);
                    Console.WriteLine("Please Try Again!");
                }
            }
        }
        Console.WriteLine("Done!");
        Console.WriteLine("Program will now exit(Enter to continue)");
        Console.ReadLine();
    }
    public static System.Drawing.Bitmap Combine(string[] files)
    {
        //read all images into memory
        List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
        System.Drawing.Bitmap finalImage = null;

        try
        {
            int width = 0;
            int height = 0;

            foreach (string image in files)
            {
                //create a Bitmap from the file and add it to the list
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);

                //update the size of the final bitmap
                width += bitmap.Width;
                height = bitmap.Height > height ? bitmap.Height : height;

                images.Add(bitmap);
            }

            //create a bitmap to hold the combined image
            finalImage = new System.Drawing.Bitmap(width, height);

            //get a graphics object from the image so we can draw on it
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
            {
                //set background color
                g.Clear(System.Drawing.Color.Black);

                //go through each image and draw it on the final image
                int offset = 0;
                foreach (System.Drawing.Bitmap image in images)
                {
                    g.DrawImage(image,
                      new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
                    offset += image.Width;
                }
            }

            return finalImage;
        }
        catch (Exception ex)
        {
            if (finalImage != null)
            {
                finalImage.Dispose();
            }
            Console.WriteLine(ex);
            throw ex;
            Console.WriteLine("Press Enter to continue...");
            Console.ReadLine();
        }
        finally
        {
            //clean up memory
            foreach (System.Drawing.Bitmap image in images)
            {
                image.Dispose();
            }
        }
    }
}

Any help will be appreciated
EDIT: I have found the cause for this error it was to do with creating stitchedImage… however now I get a Memory Exception… then again loading 350 odd images into the MemoryStream is fatal :/

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

    Okay guys I found the problem… it’s GDI+’s limit… because the size of the images is 512*512 the GDI+ limit is reached with 127 images that’s why I have my next question here

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

Sidebar

Related Questions

Okay, I've set up a bit of code which searching for all the pages
Okay, so I have the weirdest problem right now. My code is fine! It
Okay so my question is this. Say I have a simple C++ code: #include
Okay, i was wondering how to remove one line of code from all my
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I have the following create action #posts_controller, nested resource under discussions def create
Okay, so I have my post.php page. If you are not logged in, you'll
Okay - I have a dilemma. So far my script converts page titles into
okay, i'm setting up a multi-user chat system. i have a messages table, that

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.