?
Solved

Fast bitmap creation

Posted on 2011-02-21
3
Medium Priority
?
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 2000 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 86

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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