DEV/DEV2.1/TP7/ImageColorer.java

39 lines
768 B
Java
Raw Normal View History

2023-05-09 11:23:33 +02:00
import java.awt.image.*;
import javax.swing.JComponent;
import java.awt.Graphics;
public class ImageColorer extends JComponent
{
private BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
public ImageColorer(String hex)
{
super();
int rgb = Integer.parseInt(hex,16);
for(int y=0;y<1024;y++)
{
for (int x=0;x<768;x++)
{
this.img.setRGB(x,y,rgb);
}
}
}
@Override
protected void paintComponent(Graphics pinceau)
{
Graphics secondPinceau = pinceau.create();
if(this.isOpaque())
{
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight());
}
secondPinceau.drawImage(this.img,0,0,this);
}
}