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.