0

I'm new to Java and am trying to implement a Java IP camera viewer but I'm stuck on my code, I just cannot get it to work. Any help would be appreciated!

public class pleaseWork {

    public static void main(String [] args)
    {

        Image image = null;

          try {
              // Read from a file
              URL url = new URL("http://192.0.0.0:8080/?action=stream");

                // Get the input stream through URL Connection
              URLConnection con = url.openConnection();
              InputStream is = con.getInputStream();
              // Read from a URL

              byte[] buffer = new byte[33534];
              int bytesRead;
              ByteArrayOutputStream output = new ByteArrayOutputStream();
              while ((bytesRead = is.read(buffer)) != -1)
              {
                 output.write(buffer, 0, bytesRead);

              }  
             InputStream in = new ByteArrayInputStream(buffer);
             BufferedImage image = ImageIO.read(in);
             JFrame frame = new JFrame();
             JLabel label = new JLabel(new ImageIcon(image));
             frame.getContentPane().add(label, BorderLayout.CENTER);
             frame.pack();
             frame.setVisible(true);

          } catch (IOException e) {

          }
          // Use a label to display the image
    }
}

At first i implemented readLine which allowed me to see the header file and boundary with all the symbols or pixels in between, my understating is that i have to turn these symbols between the header and boundary into a byte array so as i can retrieve a image displaying this in a JFrame viewing a live stream.

GasCan
  • 36
  • 4
  • check this out http://stackoverflow.com/questions/11487251/best-way-to-access-web-camera-in-java – 11thdimension Dec 14 '15 at 22:42
  • It would be great if you could correct your code indentation and explain a bit more what you mean by stuck. Is there a stacktrace? Do you see a trace output? – ibizaman Dec 14 '15 at 22:46

0 Answers0