16

I have a tileset but all the tiles are in one image. I want to get every tile in some kind of bitmap or image array. Is there some kind of method that does that?

Bosak
  • 2,103
  • 4
  • 24
  • 43

1 Answers1

30

Use Bitmap.Clone(Rectangle, PixelFormat) , Here we can set PixelFormat of new image and the size of the rectangle

// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");

// Clone a portion of the Bitmap object.
Rectangle cloneRect = new Rectangle(0, 0, 100, 100);
Bitmap cloneBitmap = myBitmap.Clone(cloneRect, myBitmap.PixelFormat);

// Draw the cloned portion of the Bitmap object.
e.Graphics.DrawImage(cloneBitmap, 0, 0);
Andrew_STOP_RU_WAR_IN_UA
  • 9,318
  • 5
  • 65
  • 101
Damith
  • 62,401
  • 13
  • 102
  • 153