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
| int nbBitsPerPixel = 4;
int nbColors = 16;
// définition des couleurs possibles (ici 16 niveaux de gris)
byte[] reds = {
(byte)0x00, (byte)0x11, (byte)0x22, (byte)0x33, (byte)0x44, (byte)0x55, (byte)0x66, (byte)0x77,
(byte)0x88, (byte)0x99, (byte)0xAA, (byte)0xBB, (byte)0xCC, (byte)0xDD, (byte)0xEE, (byte)0xFF};
byte[] greens = {
(byte)0x00, (byte)0x11, (byte)0x22, (byte)0x33, (byte)0x44, (byte)0x55, (byte)0x66, (byte)0x77,
(byte)0x88, (byte)0x99, (byte)0xAA, (byte)0xBB, (byte)0xCC, (byte)0xDD, (byte)0xEE, (byte)0xFF};
byte[] blues = {
(byte)0x00, (byte)0x11, (byte)0x22, (byte)0x33, (byte)0x44, (byte)0x55, (byte)0x66, (byte)0x77,
(byte)0x88, (byte)0x99, (byte)0xAA, (byte)0xBB, (byte)0xCC, (byte)0xDD, (byte)0xEE, (byte)0xFF};
IndexColorModel colorModel = new IndexColorModel(nbBitsPerPixel, nbColors, reds, greens, blues);
int width = 640;
int height = 480;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY, colorModel);
WritableRaster raster = image.getRaster();
// Mettre la couleur numéro 15 au pixel (5,5)
int x = 5;
int y = 5;
int band = 0; // pas de concept de bande en couleurs indexées.
int color = 15;
raster.setSample(x, y, band, 15);
// Récupérer quelle est la couleur au pixel (10, 10)
color = raster.getSample(10, 10, band); |
Partager