read and process a pcx file

Hello all!
Im trying to develop a turn based game using swing. The game will use tiles for the board, so the problem i am currently facing is how to create the terrain. As for now. i have a pcx file with all the terrain tiles i would like to use. but i dont know how to read and extract parts of it. the pcx file is a grid with all the images (when i open it with photoshop)
The problem is a 3 part problem:

  1. read the pcx file
  2. extract the images to an array or something.
  3. paint the images.

i was looking around and find a nice little class in the midp 2.0 called TiledLayer which is exactly what i need.
can you guys help me to either be able to use that class or to solve the problem some other way?

thanks in advance.

You can Google for the PCX specification, but I doubt you’ll implement your own loader. The easiest way to load the pic is to save if in a format that ImageIO or Toolkit supports. Best would be PNG then, as it is lossless.

I quickly read the PCX specification and it doesn’t seem all that complex, so it’s up to you.

Saving it in a format readable sounds ok, the other part… reading parts of it its what bothers me.

for instance, the file contains four images like this:


| | |
| 1 | 2 |
|||
| | |
| 3 | 4 |
|||

is there any way to read them and store them in an array or do i have to edit the picture to produce 4 different files??? im asking because the file contains over a hundred pics

you can create small images in your app and render the big image in top of them, with the correct offsets.

Like:
Source image: 256x256px
4 sub images: 128x128px

for(…)
sub[n].getGraphics.drawImage(sourceImage, x, y, null);

wow, this sounds exactly like what im looking for.

can i store the results of drawImage in a variable so i dont have to call drawimage everytime i want to draw it?

The sub[n].getGraphics.drawImage(sourceImage, x, y, null); in this case I believe to be an array of BufferedImages, so once you draw to it, it’s there until you want to change it! So you would just need to override the paint(Graphics g) and do a g.drawImage() with the appropriate sub[n].

thanks a lot folks,
i will start coding soon, im still on the final details of the design phase. i will post here if i run into any trouble.