Encode data into pixels in an image

What I want to do is make a level in paint.net by drawing certain colored pixels and having the Level class decode this into an array of tiles, and if I want an entity to spawn on a certain tile, put the info necessary into the right pixel on the .png for the level.

Is this possible at all? How do I put the data into the image? How do I read the data from the image?

If this is possible, thanks, if not, sorry for wasting your time.

| Nathan

You just get the raster from the image, and change the color-data.

To load: Get the pixel data from the image (Depending on what library you’re using the method to get the data this will differ, though not too considerably), then you iterate through each pixel and get the color data from it. From there, you should be able to take information out of that value (Either by using a set of if statements, a switch, maybe even using several arrays filled with the corresponding data you need, etc.)

To edit/paint: This is more complicated. If you’re using Paint.net (Which I’ve used for a simplified version of this) then you just have to be very specific about how you fill in the values of the color (Use the ‘More >>’ to be able to pick a specific color value). Then you just fill in the specific pixel with that data. The main issue is that if you’re using each color channel (including Alpha) to mean something different you have to get that color (Using the eye drop) edit it using the color panel, then refill it in.

For anything complicated, attempting to draw it all using Paint.net is probably going to be more difficult to keep straight than writing your own tile editor system (Even if it outputs data in the form of an image).

For other information about doing this: This post is about the same thing and so is this thread.

Or if that’s too complicated, create a BufferedImage and draw on it based on your data. I usually use it for small retro style pic. But you better use Ultroman’s.

Also: for ease create an index-palette on the picture itself.

I usually create a row of differenly colored pixels in the top left.
Treating the first line of the picture as reference.
A Magenta colored pixel (255,0,255) marks the end of the index.

Now you can just easily pic the appropriate color when drawing the map, and
add more later if needed.

When loading, you first analyse this first row to get the colorvalues,
and map it to your object-index.
like
color #0 empty
color #1 sand
color #2 rock
color #3 spawn monster.

The top row is ignored, the rest of the picture defines the tile-level.