Question: I have a PNG of a deck of cards as 1 image (it has all 52 cards combined into 1 image file). How do I extract an individual card out as I need it (or extract them all into separate image files at start up).

I understand the logic of know which row and column to get, its the actual image manipulation code I am having trouble with.

I am using Visual Studio 2010 and using VB (although sample code in any .NET language would do).

I am not allowed to post the image itself, but here is an example image

<http://www.jfitz.com/cards/windows-playing-cards.png>

Thanks.

Answer: 
This will load the original and create a cropped version starting at (0,0) and with dimensions of 100x100. You'd have to write the logic to iterate over each card, know when to move to the next row, etc. However, this should help you with pulling out the cards once you know the coordinates and dimensions.

```
Bitmap cards = new Bitmap(@"C:\SomePath\");
Rectangle srcRect = new Rectangle(0, 0, 100, 100);
Bitmap card = (Bitmap)cards.Clone(srcRect, cards.PixelFormat);

```

BTW, I didn't include the call to card.Save() because there are a lot of options to set during a save and it's a bit outside of the scope of your question. However, for information on how to save it to disk, [see http://msdn.microsoft.com/en-us/library/ytz20d80.aspx](http://msdn.microsoft.com/en-us/library/ytz20d80.aspx).
```
public static System.Drawing.Image CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)
        {
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(cropX, cropY, cropWidth, cropHeight);
            System.Drawing.Image cropped = bitmap.Clone(rect, bitmap.PixelFormat);
            return cropped;
        }

```