From: <mar...@gm...> - 2007-09-28 18:25:59
|
Hello, I'm having a strange problem with the data from the camera compress device (device index = 1), it is not ready, except for the first time it runs, so I can only see one image in the application and after that the while loop goes forever. When I use the camera device it works fine, there is always data ready, but I don't know how to show that kind of data as an image. Sometimes when the program is in the while loop I get this message: 28/09/2007 01:15:41 PM javaclient2.PlayerClient read WARNING: [PlayerClient]: Unknown message subtype received in read () I also know Player is working fine, I have probed it with playercam. So here is my code: import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.awt.Graphics; import java.io.*; import javax.imageio.*; import javaclient2.CameraInterface; import javaclient2.structures.camera.PlayerCameraData; import javaclient2.PlayerClient; import javaclient2.PlayerException; import javaclient2.structures.PlayerConstants; public class CameraJPEG extends JFrame{ PlayerClient client = null; CameraInterface cami = null; PlayerCameraData camera = null; BufferedImage image = null; static byte[] img; InputStream stream; public CameraJPEG() { super("CameraJPEG"); Container container = getContentPane(); container.setLayout(null); container.setBackground(new Color(201, 199, 192)); setBounds(0,0,500,400); setVisible(true); try{ client = new PlayerClient("192.168.1.101", 6665); cami = client.requestInterfaceCamera(1, PlayerConstants.PLAYER_OPEN_MODE); } catch(PlayerException e) { e.printStackTrace(); } client.setNotThreaded(); camera = new PlayerCameraData(); try { Thread.sleep (1000); } catch (Exception e) {} while (true) { repaint(); client.requestDataDeliveryMode( PlayerConstants.PLAYER_DATAMODE_PULL); client.readAll(); client.requestAddReplaceRule (-1, -1, PlayerConstants.PLAYER_MSGTYPE_DATA, -1, 1); client.readAll(); while (!cami.isDataReady ()); camera = cami.getData(); img = camera.getImage(); stream = new ByteArrayInputStream(img,0, camera.getImage_count ()); try{ image = ImageIO.read(stream); } catch(Exception e) { e.printStackTrace(); } try{ stream.close(); } catch(IOException e) { e.printStackTrace(); } } } public void paint(Graphics g) { if (image != null) { g.drawImage(image, 0, 0, null); } else { g.clearRect(0, 0, getWidth(), getHeight()); g.drawString("Please Wait", 50, 100); } } public static void main(String[] args) { CameraJPEG aplication = new CameraJPEG(); aplication.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } So, if anyone can help me i would really appreciate it. Thanks. Marcela |