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
|
private void griseFond(BufferedImage fond) {
Graphics g= fond.getGraphics();
for (Polygone zone : lesZones) {
int x0 = (int) zone.getxMin();
int y0 = (int) zone.getyMin();
int LL = (int) zone.getLargeur();
int HH = (int) zone.getHauteur();
BufferedImage imgRendu = new BufferedImage(LL, HH, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2r = (Graphics2D) imgRendu.getGraphics();
g2r.drawImage(fond, 0, 0, LL, HH, x0, y0, x0 + LL - 1, y0 + HH - 1, null);
BufferedImage imgMasq = new BufferedImage(LL, HH, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2m = (Graphics2D) imgMasq.getGraphics();
g2m.setColor(Color.WHITE);
g2m.fillRect(0, 0, LL, HH);
g2m.setColor(Color.BLACK);
int lesX[] = getLesX(zone, 1, x0);
int lesY[] = getLesY(zone, 1, y0);
g2m.fillPolygon(lesX, lesY, lesX.length);
int noir = Color.BLACK.getRGB();
int blanc = Color.WHITE.getRGB();
for (int x = 0; x < LL; x++) {
for (int y = 0; y < HH; y++) {
int col = imgRendu.getRGB(x, y);
int msk = imgMasq.getRGB(x, y);
if (msk == noir) {
Color gris = new Color(col);
int val = (gris.getRed() + gris.getGreen() + gris.getBlue()) / 3;
gris = new Color(val, val, val);
imgRendu.setRGB(x, y, gris.getRGB());
}
if (msk == blanc) {
imgRendu.setRGB(x, y, 0x00FFFFFF);
}
}
}
g.drawImage(imgRendu, x0, y0, x0 + LL - 1, y0 + HH - 1,0, 0, LL, HH, null);
}
g.dispose();
} |
Partager