Solved

Fast bitmap creation

Posted on 2011-02-21
3
683 Views
Last Modified: 2012-05-11
Hello experts.

Decided to write a simple game using C#.
I know that it is not the best choice for the task but I have my reasons to do it.

Board for my game consists of 30 pieces.
Every piece is a bitmap 30x30 pixels.

This is how I create my board now:

 
Bitmap result = new Bitmap(30 * 30, 30 * 30);

for (int i = 0; i < 30; i++)
{
	for (int j = 0; j < 30; j++)
	{
		Bitmap small = new Bitmap(aImageList.Images[someIndex]);
		
		for (int k = 0; k < 30; k ++)
		{
			for (int l = 0; l < 30; l ++)
			{
				result.SetPixel(i * 30 + k, j * 30 + l, small.GetPixel(k, l));
				
			}
		}
	}
}

Open in new window


It takes ages to do it.

How can I make the same task faster?

Thank you

panJames
0
Comment
Question by:panJames
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
Comment Utility
Dont use GetPixel every time.

Here's what I wound up creating:

www.ai.uga.edu/mc/CovingtonImageProcessing.zip

I ended up using LockBits and Marshal.Copy to copy the image data into an array, then doing
the opposite after processing. That way I don't have to do a method call on
every single pixel, especially when doing things like convolutions.
this saves you great amount of time in processing and hence the program is fast.
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Haven't looked closely at the code...but can't you use DrawImage() instead to place each Bitmap in the correct position?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now