Cutting an image into sections
Ok so I'm working on an app that takes an image and cuts it into 16 pieces for a small puzzle game. The problem is how to do this. The solution is GDI+ to the rescue! I found some help on MSDN to eventually get this code. My puzzle needs to be 16 pieces and each piece is a small section of a larger bitmap. // get the piece width and height pieceWidth = _originalImage.Width / 4; pieceHeight = _originalImage.Height / 4; // clear the existing puzzle _puzzle.Clear(); for( int i = 0; i { for( int j = 0; j { Rectangle srcRect = new Rectangle( i * pieceWidth, j * pieceHeight, pieceWidth, pieceHeight ); // Create the new bitmap and associated graphics object Bitmap bmp = new Bitmap( pieceWidth, pieceHeight ); Graphics g = Graphics.FromImage( bmp ); ...