c# graphics for a card game

the_b1ackfox used Ask the Experts™
Hello Experts!!!

How do you get individual cards out of an image where they are all together (see attached pic)...  Is this the standard way of generating cards, is there a better way?  (Like having individual graphics in a resource file)

I'd like to know the how, the why and the best practices;  References are awesome, experience is awesome (er), lol

Thank you in advance,

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
I can't speak to best practices since I don't do game or graphics programming, but in its simplest form you simply need to load the sprite into memory, and then read a block of pixels from the original image. You should already know how large each card is--I would assume them all to be the same size. You should also know how many are in a row, and how many rows you have. Therefore, it's a simple matter of math to grab any particular card from the original image. The hardest part might be recreating the header information...but I would think you'd only have to do that once--every card could reuse that same header info.

We would need to know what kind of project this is, though. The process for implementing this would be slightly different for Windows Forms, WPF, and ASP.NET.


It isn't for a project...  Well, not yet.  I am asking so I can understand the process, I may apply this with a simple card game down the line.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial