Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fast bitmap creation

Posted on 2011-02-21
3
Medium Priority
?
696 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: 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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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