Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Encode data into pixels in an image  (Read 908 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Posted 2012-07-30 18:05:54 »

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

Check out my website!
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #1 - Posted 2012-07-30 18:07:03 »

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

- Jonas
Offline UprightPath
« Reply #2 - Posted 2012-07-30 23:19:26 »

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-07-31 01:47:38 »

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.

Offline Damocles
« Reply #4 - Posted 2012-07-31 07:54:01 »

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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!