IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

Ajouter du texte à une image


Sujet :

Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 15
    Points : 6
    Points
    6
    Par défaut Ajouter du texte à une image
    Bonjour à tous,

    Y a-il un moyen pour ajouter du texte (avec une couleur prédéfinie) à une image en java.
    Par exemple ajouter du texte dans un point bien précis sur un plan.

    Merci d'avance.
    Bonne journée à tous.

  2. #2
    Membre confirmé
    Avatar de william44290
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Juin 2009
    Messages
    400
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France

    Informations professionnelles :
    Activité : Responsable de service informatique

    Informations forums :
    Inscription : Juin 2009
    Messages : 400
    Points : 575
    Points
    575
    Par défaut
    oui voici un exemple :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    package launch;
    import java.awt.AWTException;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.image.BufferedImage;
    import java.awt.image.ConvolveOp;
    import java.awt.image.Kernel;
     
    import javax.swing.JWindow;
    import javax.swing.UIManager;
     
    public class ShadowedWindow extends JWindow {
    	private static final long serialVersionUID = 1L;
    	private BufferedImage splash = null;
        int extra = 14;
        static final Font FONTNORMAL = UIManager.getFont("Label.font").deriveFont(Font.PLAIN,UIManager.getFont("Label.font").getSize());
        static final Color 	INVALIDE_FG_RED = Color.RED;
        public ShadowedWindow(BufferedImage image) {
        	this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) ) ;
            createShadowPicture(image);
        }
     
        public void dispose(){
        	this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) ) ;
        	super.dispose();
        }
        public void paint(Graphics g) {
            if (splash != null) {
                g.drawImage(splash, 0, 0, null);
            	g.drawLine(0,0,1,this.getHeight()-extra-2);
            	g.drawLine(0,0,this.getWidth()-extra-2,1);
                g.setFont(FONTNORMAL.deriveFont(Font.BOLD,15f));
                g.setColor(INVALIDE_FG_RED);
                g.drawString("Mise à jour en cours, Merci de patienter", 40, this.getHeight()-200);
            }
        }
     
        private void createShadowPicture(BufferedImage image) {
            int width = image.getWidth();
            int height = image.getHeight();
     
            setSize(new Dimension(width + extra, height + extra));
            setLocationRelativeTo(null);
            Rectangle windowRect = getBounds();
     
            splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D) splash.getGraphics();
     
            try {
                Robot robot = new Robot(getGraphicsConfiguration().getDevice());
                BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width + extra, windowRect.height + extra));
                g2.drawImage(capture, null, 0, 0);
            } catch (AWTException e) { }
     
            BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); 
            Graphics g = shadow.getGraphics();
            g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
            g.fillRoundRect(6, 6, width, height, 12, 12);
     
            g2.drawImage(shadow, getBlurOp(7), 0, 0);
            g2.drawImage(image, 0, 0, this);
        }
     
        private ConvolveOp getBlurOp(int size) {
            float[] data = new float[size * size];
            float value = 1 / (float) (size * size);
            for (int i = 0; i < data.length; i++) {
                data[i] = value;
            }
            return new ConvolveOp(new Kernel(size, size, data));
        }
     
    //    public static void main(String[] args) {
    //        try {
    //            BufferedImage image = ImageIO.read(ShadowedWindow.class.getResourceAsStream("aImages/binaire.png"));
    //            ShadowedWindow window = new ShadowedWindow(image);
    //            window.setVisible(true);
    //            Timer timer = new Timer(5000, new ActionListener() {
    //                public void actionPerformed(ActionEvent evt) {
    //                    System.exit(0);
    //                }
    //            });
    //            timer.start();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }
    //    }
    }

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 15
    Points : 6
    Points
    6
    Par défaut
    Je vais essayer ce code.
    Merci pour votre réponse.

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 15
    Points : 6
    Points
    6
    Par défaut
    J'ai adapté le code et ça fonctionne bien. merci pour votre aide.
    Puis-je récupérer le texte d'un fichier ".txt" par exemple.

    Merci d'avance.

  5. #5
    Membre confirmé
    Avatar de william44290
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Juin 2009
    Messages
    400
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France

    Informations professionnelles :
    Activité : Responsable de service informatique

    Informations forums :
    Inscription : Juin 2009
    Messages : 400
    Points : 575
    Points
    575
    Par défaut
    un exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    	public static String[] readParamFromFile(String file,int nbParam){
    		String [] ret=new String [nbParam];
    		if (Gp.isFileExists(file)){
    			try {
    				Scanner scanner = new Scanner(new File(file));
    				for (int i=0;i<nbParam;i++){
    					if (scanner.hasNextLine()){
    						ret[i]=scanner.nextLine();
    					} else {
    						ret[i]="";
    					}
    				}
    				scanner.close();
    				scanner=null;
    			} catch (FileNotFoundException arg0) { arg0.printStackTrace(); }
    		} else {
    			ret=null;
    		}
    		return ret;
    	}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouter du texte à une image
    Par Thomas Lebrun dans le forum Contribuez
    Réponses: 3
    Dernier message: 01/11/2013, 16h39
  2. Réponses: 13
    Dernier message: 15/05/2012, 21h44
  3. Ajouter du texte à une image
    Par Thomas Lebrun dans le forum Contribuez
    Réponses: 0
    Dernier message: 29/12/2010, 10h52
  4. [MFC] ajouter du texte à une Cedit
    Par helww dans le forum MFC
    Réponses: 4
    Dernier message: 06/09/2007, 17h57
  5. Ajouter du texte à une variable
    Par micatmidog dans le forum Langage
    Réponses: 2
    Dernier message: 28/09/2005, 19h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo