Uuuuh mediatracker ;D
ImageIO is nicer.
import javax.imageio.ImageIO;
[...]
BufferedImage img = javax.imageio.ImageIO.read(getClass().getResource("/gfx/set.gif"));
This kind of images (from imageio) will be managed by default with 1.5. With 1.4 you have to copy em once (as seen before).
If you are writing an (J)Applet or a non signed webstart application do this at the very beginning:
ImageIO.setUseCache(false);
(caching needs writing permissions doh)
I always have the feeling dealing with 2D images is complicated.
Basic stuff is pretty easy once you’ve figured it out (btw the way I did that multi color versions is the hard way to do it).
Well, ImageIO is pretty neat. The ‘o’ there is “out”, you can also write files with it.
import java.awt.*;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
public class C4096
{
public static void main(String[] args)
{
BufferedImage outImage = new BufferedImage(16,256,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = outImage.createGraphics();
int x=0;
int y=0;
int c=0;
for(int r=0;r<16;r++)
{
for(int g=0;g<16;g++)
{
for(int b=0;b<16;b++)
{
//g2d.setColor(new Color(r*16,g*16,b*16));
g2d.setColor(new Color(g*17,r*17,b*17));
g2d.fillRect(x,y,x+1,y+1);
c++;
x++;
//if(x==64)
if(x==16)
{
x=0;
y++;
}
System.out.println(r+"/"+g+"/"+b);
}
}
}
System.out.println("colors:"+c);
g2d.dispose();
try
{
ImageIO.write(outImage, "png", new File("4096.png"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
That for example creates a nice little image with all 4096 colors you have in 12bit mode. It looks like this (but rotated by 90°)
The reason for changing the the setColor method parameters was giving a better contrast variation across the image. Green appears to be the brightest color, therefore it gets one bit more in 16bit (5-6-5) and for that reason I decided to spread the green part across the whole image 