A voir également:
- Java pixel
- Waptrick java football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Jeux java itel football - Télécharger - Jeux vidéo
- Waptrick java ✓ - Forum Mobile
- Jeux java itel 5360 ✓ - Forum Mobile
5 réponses
Utilisateur anonyme
7 avril 2007 à 06:43
7 avril 2007 à 06:43
Salut!
Ce que tu dois faire, c'est utiliser une BufferedImage sur laquelle tu dessines.
Pour modifier un pixel sur l'image appelle la méthode setRGB(int x, int y, int rgbColor).
Une fois ton image complètement dessinée, dans la méthode paint(Graphics g) de ton composant (un JPanel dans l'exemple ci-dessous) fais ceci:
Vois la démo ci-dessous qui dessines un point rouge à l'endroit où tu cliques:
;-)
HackTrack
Ce que tu dois faire, c'est utiliser une BufferedImage sur laquelle tu dessines.
Pour modifier un pixel sur l'image appelle la méthode setRGB(int x, int y, int rgbColor).
Une fois ton image complètement dessinée, dans la méthode paint(Graphics g) de ton composant (un JPanel dans l'exemple ci-dessous) fais ceci:
g.drawImage(tonImage,0,0,null);
Vois la démo ci-dessous qui dessines un point rouge à l'endroit où tu cliques:
import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; /** * Created on 07-avr.-07 * * @author: HackTrack */ public class PixelDemo extends JFrame { private Container c; public PixelDemo() { super("Pixel demo"); this.initialize(); } private void initialize() { setDefaultCloseOperation(EXIT_ON_CLOSE); c = getContentPane(); JPanel panel = new DemoPanel(); panel.setPreferredSize(new Dimension(320, 200)); c.add(panel); } class DemoPanel extends JPanel { private BufferedImage img; public DemoPanel() { super(); this.initialize(); } private void initialize() { img = new BufferedImage(320, 200, BufferedImage.TYPE_INT_ARGB); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); img.setRGB(x, y,Color.red.getRGB()); repaint(); } }); } public void paint(Graphics g) { g.drawImage(img, 0, 0, null); } } public static void main(String[] args) { PixelDemo demo = new PixelDemo(); demo.pack(); demo.setVisible(true); } }
;-)
HackTrack
Salut et merci à toi de ton aide!
J'ai essayé de suivre ta démarche, et voici le code source d'un essai pour coloriser un pixel sur deux en noir ou blanc mais il ne marche pas, et je ne comprends pas le problème. Tout se passe bien en compilant et executant mais rien ne s'affiche...
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class Essai extends JFrame
{
Container c = getContentPane();
public Essai()
{
super();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Essai");
JPanel panel = new EssaiPanel();
panel.setPreferredSize(new Dimension(300,300));
c.add(panel);
pack();
setVisible(true);
}
public static void main(String[] args)
{
new Essai();
}
}
class EssaiPanel extends JPanel
{
BufferedImage img = new BufferedImage(300,300,BufferedImage.TYPE_INT_ARGB);
int col=0;
int i=0;
int j=0;
public EssaiPanel()
{
super();
for(i=0;i<300;i++)
{
for(j=0;j<300;j++)
{
col=j%2*255;
img.setRGB(i,j,col);
repaint();
}
}
setVisible(true);
}
public void paint(Graphics g)
{
g.drawImage(img,0,0,null);
}
}
Si tu pouvais m'aider... Merci d'avance! @+
J'ai essayé de suivre ta démarche, et voici le code source d'un essai pour coloriser un pixel sur deux en noir ou blanc mais il ne marche pas, et je ne comprends pas le problème. Tout se passe bien en compilant et executant mais rien ne s'affiche...
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class Essai extends JFrame
{
Container c = getContentPane();
public Essai()
{
super();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Essai");
JPanel panel = new EssaiPanel();
panel.setPreferredSize(new Dimension(300,300));
c.add(panel);
pack();
setVisible(true);
}
public static void main(String[] args)
{
new Essai();
}
}
class EssaiPanel extends JPanel
{
BufferedImage img = new BufferedImage(300,300,BufferedImage.TYPE_INT_ARGB);
int col=0;
int i=0;
int j=0;
public EssaiPanel()
{
super();
for(i=0;i<300;i++)
{
for(j=0;j<300;j++)
{
col=j%2*255;
img.setRGB(i,j,col);
repaint();
}
}
setVisible(true);
}
public void paint(Graphics g)
{
g.drawImage(img,0,0,null);
}
}
Si tu pouvais m'aider... Merci d'avance! @+
Utilisateur anonyme
9 avril 2007 à 14:22
9 avril 2007 à 14:22
Salut!
;-)
HackTrack
import java.awt.*; import java.awt.image.*; import javax.swing.*; public class Essai extends JFrame { Container c = getContentPane(); public Essai() { super(); setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("Essai"); JPanel panel = new EssaiPanel(); panel.setPreferredSize(new Dimension(300, 300)); c.add(panel); } class EssaiPanel extends JPanel { private BufferedImage img; private int col = 0; private int i = 0; private int j = 0; public EssaiPanel() { super(); } public void paint(Graphics g) { int imgWidth = getWidth(); int imgHeight = getHeight(); img = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); for (i = 0; i < imgWidth; i++) { for (j = 0; j < imgHeight; j++) { col = (j % 2==0?Color.BLACK.getRGB():Color.WHITE.getRGB()); img.setRGB(i, j, col); } } g.drawImage(img, 0, 0, null); } } public static void main(String[] args) { System.out.println(Color.BLACK.getRGB()+","+Color.WHITE.getRGB()); Essai essai = new Essai(); essai.pack(); essai.setVisible(true); } }
;-)
HackTrack
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question