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 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| public static Vector<BufferedImage> createZoomImg (Image aImgBase, int[] aListetaille, Color aCouleurContour)
{
Vector<BufferedImage> vectReturn = new Vector<BufferedImage> ();
for (int i = 0 ; i < aListetaille.length ; i++ )
{
int tailleCourante = aListetaille[i];
// redimention de l'image
BufferedImage newImage = OutilImage.scaleImage (aImgBase, tailleCourante, tailleCourante);
int taXFimg = (int) ((Math.sqrt ((Math.pow (tailleCourante/2, 2)- Math.pow (tailleCourante/4, 2))))*2);
int taYFimg = tailleCourante;
int p0xFimg = (tailleCourante - taXFimg)/2;
int p0yFimg = 0;
BufferedImage intImage = newImage.getSubimage (p0xFimg, p0yFimg, taXFimg, taYFimg);
// retaillage selon le polygone
Polygon poly = OutilMap.getHexa (tailleCourante, new Point (0, 0));
int x = 0;
int y = 0;
while(x < intImage.getWidth ())
{
while (y < intImage.getHeight ())
{
Color couleurPixel = new Color (intImage.getRGB (x, y));
if (!poly.contains (x, y) || (couleurPixel.getBlue () == 255 && couleurPixel.getGreen () == 255 && couleurPixel.getRed () == 255 ))
{
intImage.setRGB (x, y, new Color (couleurPixel.getRed (), couleurPixel.getGreen (), couleurPixel.getBlue (), 0).getRGB ());
}
y ++;
}
x ++ ;
y = 0;
}
// traçage d'un polygone pour le contour
Graphics2D g = intImage.createGraphics ();
g.setColor (aCouleurContour);
g.drawPolygon (poly);
g.dispose ();
vectReturn.add (intImage);
}
return vectReturn;
}
public static BufferedImage scaleImage (Image source, int width, int height)
{
BufferedImage img = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics ();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g.drawImage (source, 0, 0, width, height, null);
g.dispose ();
return img;
} |
Partager