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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import java.awt.image.*;
//dans mon thread
(...)
ImageIcon[] arr_Img = new ImageIcon[7];
arr_Img[6] = new javax.swing.ImageIcon(getClass().getResource(str_url+"1.png"));
Value_1 = elm_player.getElementsByTagName("value").item(0).getFirstChild().getNodeValue();
MonJLabel.setIcon(SetImg(Value_1));
(...)
public ImageIcon SetImg(String str_Value)
{
ImageIcon ImageIcon_Img = null;
BufferedImage BufferedImage_Img = null;
BufferedImage BufferedImage_Current;
BufferedImage_Current = toBufferedImage(arr_Img[6].getImage());
for (int int_Index = 1; int_Index <= int_Nb; int_Index++)
{
BufferedImage_Img = addImage(BufferedImage_Img, BufferedImage_Current);
}
if (BufferedImage_Img != null)
{
ImageIcon_Img = new ImageIcon(BufferedImage_Img);
}
return ImageIcon_ChipsImg;
}
private BufferedImage addImage(BufferedImage BufferedImage_1, BufferedImage BufferedImage_2)
{
final int int_y_translate = 2;
int int_Width, int_Height;
if (BufferedImage_1 != null)
{
int_Width = BufferedImage_1.getWidth(null);
int_Height = BufferedImage_1.getHeight(null);
}
else
{
int_Width = BufferedImage_2.getWidth(null);
int_Height = BufferedImage_2.getHeight(null);
}
BufferedImage BufferedImage_Result = new BufferedImage(int_Width, int_Height+int_y_translate, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = BufferedImage_Result.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.drawImage(BufferedImage_1, 0, int_y_translate, null);
g2d.drawImage(BufferedImage_2, 0, 0, null);
g2d.dispose();
return BufferedImage_Result ;
}
// Passage d'un objet type "Image" à "BufferedImage"
private BufferedImage toBufferedImage(Image image)
{
// On test si l'image n'est pas déja une instance de BufferedImage
if (image instanceof BufferedImage)
{
return (BufferedImage)image;
}
else
{
// On s'assure que l'image est complètement chargée
image = new ImageIcon(image).getImage();
// On crée la nouvelle image
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image,0,0,null);
g.dispose();
return bufferedImage;
}
} |
Partager