Solved

Fast bitmap creation

Posted on 2011-02-21
3
688 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
ID: 34947992
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
ID: 34947998
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 34948424
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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