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
|
BufferedImage image = ...
int width = image.getWidth();
int height = image.getHeight();
if (image.getType() != BufferedImage.TYPE_INT_ARGB) {
BufferedImage newBi = new BuferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = newBi.createGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.dispose();
image = newBi;
}
for (int i = 0 ; i < width ; i++) {
for (in j = 0 ; j < height ; j++) {
int rgb = image.getRGB(i, j);
int red = (rgb >> 16) & 0xff;
int green = (rgb >> 8) & 0xff;
int blue = (rgb >> 0) & 0xff;
// On remplace les pixels blancs par la couleur (noire) transparente.
if ((red == 255) && (green == 255) && (blue == 255)) {
image.setRGB(i, j, 0);
}
}
} |