Solved

Fast bitmap creation

Posted on 2011-02-21
3
690 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 19

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 19

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wav problem 4 28
Close form "before" open 3 48
What is Microsoft.Exchange.WebServices.Data.ExchangeService in PowerShell? 4 33
VB.NET 2008 Winforms Signing 13 30
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 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