My favorites
▼
|
Sign in
sioti
ambiente para treinamento baseado em jogo RPG
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
sioti
/
src-batch
/
com
/
sioti
/
batch
/
MapCreator.java
r14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.sioti.batch;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.imageio.ImageIO;
public class MapCreator {
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws InterruptedException,
IOException {
// This method ensures that all pixels have been loaded before returning
// Image image = new ImageIcon("image.gif").getImage();
BufferedImage image = ImageIO.read(new File("docs/mapa.bmp"));
// Get the dimensions of the image; these will be non-negative
int width = image.getWidth(null);
int height = image.getHeight(null);
// identify the colors
char node = 'A';
Map colors = new TreeMap();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
String hex = getColor(image, x, y);
if (colors.get(hex) == null) {
colors.put(hex, Character.valueOf(node++));
}
}
}
// show the colors
Iterator iter = colors.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
System.out.println(key);
System.out.println(colors.get(key));
}
BufferedWriter writer = new BufferedWriter(new FileWriter(
"docs/mapa.txt"));
// write the file
for (int y = 0; y < height; y++) {
StringBuffer line = new StringBuffer(width);
for (int x = 0; x < width; x++) {
String hex = getColor(image, x, y);
char toWrite = ((Character) colors.get(hex)).charValue();
line.append(toWrite);
}
writer.write(line.toString());
writer.write(Character.LINE_SEPARATOR);
}
writer.flush();
writer.close();
}
private static String getColor(BufferedImage image, int x, int y) {
int c = image.getRGB(x, y);
int red = (c & 0x00ff0000) >> 16;
int green = (c & 0x0000ff00) >> 8;
int blue = c & 0x000000ff;
String hex = Integer.toHexString(red) + Integer.toHexString(green)
+ Integer.toHexString(blue);
hex = hex.toUpperCase();
return hex;
}
}
Show details
Hide details
Change log
r2
by hamilton.lima on Jun 23, 2008
Diff
first commit
Go to:
/trunk/sioti
/trunk/sioti/.project
/trunk/sioti/.settings
...ettings/org.eclipse.jdt.ui.prefs
/trunk/sioti/bin
/trunk/sioti/bin/com
.../bin/com/sioti/batch/Chunk.class
/trunk/sioti/bin/com/sioti/client
...sioti/client/CameraManager.class
...in/com/sioti/client/Client.class
.../client/TileBasedHeightMap.class
...client/ui/TestJMEDesktop$1.class
...lient/ui/TestJMEDesktop$10.class
...lient/ui/TestJMEDesktop$11.class
...client/ui/TestJMEDesktop$3.class
...client/ui/TestJMEDesktop$4.class
...client/ui/TestJMEDesktop$6.class
...client/ui/TestJMEDesktop$9.class
...i/client/ui/TestJMEDesktop.class
.../sioti/bin/com/sioti/client/util
...jme_samples/HelloAnimation.class
...ioti/jme_samples/HelloNode.class
...ti/jme_samples/HelloStates.class
...i/jme_samples/HelloTerrain.class
.../login/TestCreateProfissao.class
.../sioti/login/TestHttpLogin.class
.../com/sioti/map/NetworkUtil.class
...oti/bin/com/sioti/util/Log.class
/trunk/sioti/bin/media/Thumbs.db
/trunk/sioti/bin/media/models
/trunk/sioti/bin/media/models/alita
...in/media/models/alita/alita2.jpg
/trunk/sioti/bin/media/texture
...ioti/bin/media/texture/grass.jpg
...ti/bin/media/texture/highest.jpg
/trunk/sioti/data
/trunk/sioti/data/cursor
/trunk/sioti/data/cursor/Thumbs.db
/trunk/sioti/data/texture
/trunk/sioti/data/texture/Thumbs.db
/trunk/sioti/docs/backgrounds.svg
...ocs/diagrams/sioti_diagrama.jude
/trunk/sioti/docs/documents
...oti/docs/documents/sioti.com.jpg
...sioti/docs/ideias/JobClasses.jpg
...sioti/docs/ideias/make place.pdf
...cs/ideias/make your own room.png
/trunk/sioti/docs/jme_todo_list.txt
...cao_do_mapa.svg-rect3258-215.png
.../sioti/docs/map/mapa-changed.zip
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2209 bytes, 81 lines
View raw file
Powered by
Google Project Hosting