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

Applets Java Discussion :

Affichage Webcam applet


Sujet :

Applets Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 59
    Par défaut Affichage Webcam applet
    Bonjour,

    j'essaie de faire un applet qui affiche la webcam, mon code compilé et exécutée (Run as an applet) sous eclipse fonctionne trés bien mais quand je le déploie sur mon html ma frame n'affiche pas l'image alors que la webcam fonctionne (le témoin lumineux s'éclaire).

    Etant un noob en applet jvien vous demander un peu d'aide, merci

    voila le code:
    l'applet:
    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
     
    import java.awt.Graphics;
    import java.io.IOException;
    import javax.swing.JApplet;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class webcam extends JApplet {
    	public void init()
    	{
    		DeviceHandler dh = null;
    		try 
    		{
    			 dh = new DeviceHandler("vfw:Microsoft WDM Image Capture (Win32):0" );
    			 long time = System.currentTimeMillis();
    			 while (!dh.isReady()) {}
    				JFrame jf = new JFrame("test" );
    				       jf.setSize(640, 340);
    				JPanel jp = new JPanel();
    				       jp.setSize(100, 100);
    				jf.getContentPane().add(jp);
    				jf.setVisible(true);
    				jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    				 Graphics gc = jp.getGraphics();
    				 while (true)
    		         {
    		            if (System.currentTimeMillis() > time + 100)
    		            {
    		            	time = System.currentTimeMillis();
    		                gc.drawImage(dh.grabImage(), 0, 0, jp);
    		                //System.out.println("boucle");
    		            }
    		         }
    		} catch (IOException e) 
    		{
    			e.printStackTrace();
    		} 
    	}
    }
    la class pour gerer la webcam:
    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
     
    import java.awt.Image;
    import java.io.IOException;
    import javax.media.*;
    import javax.media.control.FrameGrabbingControl;
    import javax.media.format.VideoFormat;
    import javax.media.util.BufferToImage;
     
     public class DeviceHandler {
     
            private CaptureDeviceInfo device;
            private Player player;
            private FrameGrabbingControl frameGrabber;
            private Buffer buffer;
            private BufferToImage bufferUtil;
            private boolean ready;
            private int i;
     
           /** Creates a new instance of DeviceHandler */
           public DeviceHandler(String deviceName) throws IOException
           {//throws Exception {
               this.ready = false;
               this.device = null;
               this.device = CaptureDeviceManager.getDevice(deviceName);
               //if (this.device == null) { throw new Exception("Device : \"" + deviceName + "\" not found !" ); }
               MediaLocator ml = this.device.getLocator();
               //if (ml == null) { throw new Exception("Unable to find an appropriate media locator !" ); }
               this.player = null;
               try { this.player = Manager.createRealizedPlayer(ml); }
               catch (NoPlayerException ex) {}// throw new Exception("Unable to find an appropriate player !", ex); }
               catch (CannotRealizeException ex) {}// throw new Exception("Unable to get the player in realized state !", ex); }
               catch (IOException ex) {}// throw new Exception("Unable to create a player !", ex); }
               //if (this.player == null) { throw new Exception("Player is NULL !" ); }
               this.player.start();
               while ((this.player.getState() & Player.Started) == 0) {}
               this.ready = true;
               this.frameGrabber = (FrameGrabbingControl)this.player.getControl("javax.media.control.FrameGrabbingControl" );
               this.buffer = frameGrabber.grabFrame();
               this.bufferUtil = new BufferToImage((VideoFormat)buffer.getFormat());
               this.i = 0;
          }
     
           public Image grabImage()
           {
               this.i++;
               this.buffer = frameGrabber.grabFrame();
       // juste pour tester
                /*if (this.buffer.getData() != null)
                    System.out.println(this.buffer.getFormat().getEncoding() + " " + i);*/
               this.bufferUtil = new BufferToImage((VideoFormat)buffer.getFormat());
               return this.bufferUtil.createImage(buffer);
           }
     
           public boolean isReady()
           {
               return this.ready;
           }
       }
    la balise:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <object classid="java:webcam.class"
              codebase="bin"
              type="application/x-java-applet"
              width="300" height="80">
        alt : <a href="bin/webcam.class">webcam.class</a>
      </object>

  2. #2
    Membre Expert
    Avatar de slim_java
    Homme Profil pro
    Enseignant
    Inscrit en
    Septembre 2008
    Messages
    2 272
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Septembre 2008
    Messages : 2 272
    Par défaut
    Salut,

    pour insérer un Applet dans une page HTML, tu dois utiliser la balise
    <APPLET >...</APPLET >
    de cette manière :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     
    <APPLET code="Nom_classe_principale.class" width="largeur_applet" height="hauteur_applet">
    </APPLET>

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 59
    Par défaut
    Citation Envoyé par slim_java Voir le message
    Salut,

    pour insérer un Applet dans une page HTML, tu dois utiliser la balise de cette manière :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     
    <APPLET code="Nom_classe_principale.class" width="largeur_applet" height="hauteur_applet">
    </APPLET>
    merci, à la base je faisais comme sa, mais j'ai lu que object etait une norme pour tout les web browsers, enfin bon sa ne vient pas de la puisque mes web browser m'affiche bien mon applet, m'ouvre ma frame mais ne m'affiche pas le flux vidéo

Discussions similaires

  1. DirectShow affichage webcam dans une form
    Par TERRIBLE dans le forum API graphiques
    Réponses: 0
    Dernier message: 27/04/2008, 17h36
  2. affichage webcam dans picturebox
    Par offspring dans le forum VB.NET
    Réponses: 1
    Dernier message: 22/09/2007, 12h32
  3. Affichage Webcam dans une Applet
    Par ionix dans le forum Applets
    Réponses: 4
    Dernier message: 15/01/2006, 19h57
  4. [JSP][APPLET] probleme d'affichage d'applets
    Par spoutyoyo dans le forum Applets
    Réponses: 2
    Dernier message: 16/03/2005, 16h32

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