Fastest way to slice an image?

Defiant00

Member
Joined
Jun 8, 2003
Messages
10
Ive got an image loaded into a Bitmap object, and I need to slice it into 256x256 pieces to load as Direct3D textures.

Currently it works by creating a new Bitmap object, getting the Graphics object from it, and then doing g.DrawImage() with the specified part of the
source drawn onto the new Bitmap object.

Code:
Bitmap b = new Bitmap(256, 256);
			Graphics g = Graphics.FromImage(b);
			
			g.DrawImage(this.pic, new Rectangle(0, 0, 256, 256),
			            new Rectangle(this.xLoad * 256, this.yLoad * 256,
			                          256, 256), GraphicsUnit.Pixel);
			
			this.sprites[this.xLoad, this.yLoad] = new MySprite(d, b);
			
			b.Dispose();
			g.Dispose();

As the current method, this is much too slow. It can take 5+ seconds to load a larger image. I have tried using BitBlt, however it produces empty bitmap objects...any ideas?

Aaron
 
Last edited by a moderator:
Use Bitmap.Clone. :) I think its something like someBitmap.Clone(rect);, cant remember off the top of my head though.


Dan
 
Thanks for the response, however the current method (that is too slow as it is) is about twice as fast as using Bitmap.Clone(rectangle, pixelFormat)

Heres to hoping that someone else has a suggestion as well...
 
Back
Top