AWTLoader al = new AWTLoader();
Image i = al.load(galaxyImg, false);
Texture2D t2d = new Texture2D(i);
[/java]
but i’d like to use a more polished Asset path like “Textures/galaxy.png”, the absolute path is the evil.
How can i create a File instance starting from i.e. “Textures/galaxy.png” ?
I’ll try to use it.
I need to pass through the BufferedImage because i’ve to read (and write) the color of a pixel (x,y) of the image and with BufferedImage i use the .getRGB(x, y) method.
So i need something that load from asset to BufferedImage,
I’ll try to explain my situation.
I want to draw a galaxy map and resize it.
This map is mixed bitmap and procedural.
I mean: when i zoom in, twice or three time i want only to resize the image using a classical scale algorithm. But when you increase the magnify factor, i want to replace the single pixel with a set of random point: the number of the “stars” will depends from the value of the color: the more bright is the pixel, the more stars are inside.
For a visual demonstration please look at this link: the text is in italian but you can see only the images:
To obtain this, in a normal java jPanel, i’ve used this code:
[java]
public void drawGalaxy(Graphics2D g2d) {
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
int step = 8;
int maxx = galaxyImage.getWidth() / step;
int maxy = galaxyImage.getHeight() / step;
int startx = (galaxyImage.getWidth() - maxx) / 3;
int starty = (galaxyImage.getHeight() - maxy) / 3;
int yy = 0;
Random random = new Random();
int tot=0;
for (int x = startx; x < startx + maxx; x++) {
int xx = 0;
for (int y = starty; y < starty + maxy; y++) {
int p = galaxyImage.getRGB(x, y);
Color c = new Color(p);
if (step >= 8) {
int lum = c.getRed() / 8;
g2d.setColor(c);
for (int i = 0; i < lum; i++) {
tot=tot+lum;
int x2 = random.nextInt() % step;
int y2 = random.nextInt() % step;
g2d.drawLine(x2 + xx * step, y2 + yy * step, x2 + xx * step, y2 + yy * step);
}
} else {
g2d.setColor(c);
g2d.fill(new Rectangle2D.Double(xx * step, yy * step, step, step));
//g2d.fillRect(xx * step, yy * step, step, step);
}
xx++;
}
yy++;
}
}
[/java]
Now i need to implement it inside jMonkey. The map is a com.jme3.ui.Picture, and i think to use it to display on the screen attaching as a “gui node”.
But i’m just starting to use jmonkey, pheraps there’s a more brilliant way…
Ok, i’ve made some progress to do my stuff, but i’m a bit confused. Please apologize me, i’m starting with this beautiful engine and i’ve to learn a lot
To display my map i’m using the Picture class that seems perfect to display 2d images inside a 3d world.
this because i need to work with the pixels of the image so i need ImageRaster, so i need Image.
Well now i’ve the Image with the resized map, now i want to upgrade the Picture that is displayed on the screen.
But i’m not able to find how to pass from Image to Picture. The only method that seems interesting is setTexture of Picture, but i cannot find a way to obtain a “Texture2d” class from Image.
Also looking on ImagePainter library.
Sorry: i’ve tried to look inside the javadocs, but of Texture class, and i’ve found nothing. I haven’t look at Texture2D: i’m still a bit confused about the differences of the classes.
Anyway thank you: now it works.