I have a 256x256 *.bmp file that I am loading in and I am not quite sure what the best way to actually clip and store all 64 tiles (32x32) out of it.
In the end I want something that I can easily place onto the screen.
What would be the best way to clip portions out of an image
What kind of object would be the best way to store this information
Any advice is welcomed.

The best way to clip and store an image
dehinson
So I create an array list and a Bitmap. I copy and paste the pixels from the loaded bitmap to the new bitmap and add it to the ArrayList. Then I just set each button image from the array list.
PRIDE
Thank You PJ.
FloatingPoint
Graphics g = this.CreateGraphics();
TextureBrush TileClip = new TextureBrush(TileMap);
g.FillRectangle(TileClip, 0, 0, 32, 32);
It seems that if you draw anything from a brush or a pen, it will get erased once another window goes over it. Thats is definitely not the route I want to take since I would likely have to update it constantly.
sushila
Alexander Dsugan
public void SeperateBitmap( Bitmap source, Size chunkSize, string destinationFolder )
{
int counter = 1;
for( int y = 0; y < source.Height; y += (y + chunkSize.Height <= source.Height chunkSize.Height : source.Height - y))
{
for( int x = 0; x < source.Width; x =+ (x + chunkSize.Width <= source.Width chunkSize.Width : source.Width - x ) )
{
String filename = Path.Combine( destinationFolder, counter + ".bmp" );
Rectangle chunkBounds = new Rectangle( x, y, chunkSize.Width, chunkSize.Height );
Bitmap chunk = source.Clone( chunkBounds, source.PixelFormat );
chunk.Save( filename, ImageFormat.Bmp );
}
}
}
srinivas jani
protected override void OnPaint(PaintEventArgs e)
{
SeperateBitmapandDrawInGraphics( _myBitmap, new Size( 32, 32 ), e.Graphics );
}
public void SeperateBitmapandDrawInGraphics( Bitmap source, Size chunkSize, Graphics g )
{
for( int y = 0; y < source.Height; y += (y + chunkSize.Height <= source.Height chunkSize.Height : source.Height - y))
{
for( int x = 0; x < source.Width; x =+ (x + chunkSize.Width <= source.Width chunkSize.Width : source.Width - x ) )
{
Rectangle chunkBounds = new Rectangle( x, y, chunkSize.Width, chunkSize.Height );
Bitmap chunk = source.Clone( chunkBounds, source.PixelFormat );
// Draw the image to the graphics object.
g.DrawImageUnscaled( chunk, x, y );
}
}
}