import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; import java.io.IOException; import java.io.InputStream; import javax.microedition.media.*; public class ClassPantalla extends Canvas implements Runnable { private Image IMG1, IMG0; private Graphics IMGg1; private int[] RGB; private int W,H; private int color; private Player player=null; private VideoControl videoControl=null; public ClassPantalla() { try { player=Manager.createPlayer("capture://video"); player.realize(); videoControl=(VideoControl)(player.getControl("VideoControl")); if(videoControl!=null){ videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this); videoControl. setDisplayLocation(5,15); } }catch(IOException ioe){ }catch(MediaException me){}catch(SecurityException se){ } IMG1 = Image.createImage(128,128); if((player!=null)){ try{ player.start(); videoControl.setVisible(true); } catch(MediaException me){} catch(SecurityException se){} } } public void run() { takeSnapshot(); } public void keyPressed(int keyCode){ if(getGameAction(keyCode)==FIRE){ Thread t=new Thread(this); t.start(); } } public void takeSnapshot(){ if(player!=null){ try{ byte[] pngImage=videoControl.getSnapshot(null); System.err.println("png length:"+pngImage.length); IMG1=Image.createImage(pngImage,0,pngImage.length); color=Procesar(); repaint(); int r=((0xff0000&color)>>16); int g=((0x00ff00&color)>>8); int b=(0x0000ff&color); int col=-1; int umb=60; if((2*r-g-b)>umb) col=0; if((2*g-r-b)>umb/2) col=1; //ojo if((2*b-r-g)>umb) col=2; String[] colores={"rojo.wav", "verde.wav", "azul.wav"}; if(col>=0) try { InputStream in=getClass().getResourceAsStream(colores[col]); Player p= Manager.createPlayer(in,"audio/x-wav"); p.start(); } catch(Exception e){} }catch(MediaException me){System.err.println("err take"); } } } public int PromMascara(int[] M) { int[][] A; int f=0,c=0, r=0, g=0,aux,n=0; int b=0; A=new int[W][H]; for(int i=0;i>16); g=g+((0x00ff00&aux)>>8); b=b+(0x0000ff&aux); //OJO AGREGAR A TIPS!!!!! SIEMPRE UTILIZAR () con operador & n++; } else A[c][f]=0x0000ff; c=c+1; if(c==W) {c=0;f=f+1;} } for(f=0;f