Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

network camera java

Posted on 2006-05-11
1
Medium Priority
?
235 Views
Last Modified: 2010-03-31
im trying to catch the picture from my url address and then im trying to save but i cant save anything..i have implemented the call getnextfile...
plz help with that



import java.net.*;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

/**
 * <p>Title: Webcam</p>
 *
 * <p>Description:
 * kan hente billeder fra et AXIS 206 Network Camera</p>
 *
 * brug
 * ImageIO.write(RenderedImage im, String formatName, File output)
 * til at skive til disken BufferedImage implamentere RenderedImage
 *
 * @author Mikkel Wendt-Larsen(4312)
 * @version 1.0
 */

public class Webcamera
{
    private String ip = "212.130.239.79:5559";
    private String path = "axis-cgi/jpg/image.cgi";

    private String[] param =
        {"resolution", "compression", "color", "clock", "date"};
    private String resolution = "640x480";
    private byte compression = 10;
    private byte color = 1;
    private byte clock = 0;
    private byte date = 0;

    public Webcamera()
    {
      getDate();
      getClock();
      getResolution();
      getCompression();
      getPath();
      getIP();
      try {
        getImage();
      }
      catch (MalformedURLException ex) {
      }
    }

    /**
     * setDate
     * True hvis der skal dato på billedet
     * False hvis der ikke skal dato på billedet
     *
     * @param date boolean
     */
    public void setDate(boolean date)
    {
        //this.date = (byte)((date) ? 1 : 0);
       
        if(date==true)
          this.date = 1;
       
        else if(date==true)
       
        this.date = 0;
    }

    public boolean getDate()
    {
        return (date == 1);
    }

    /**
     * setClock
     * True hvis der skal tid på billdet
     * False hvis der ikke skal tid på
     *
     * @param clock boolean
     */
    public void setClock(boolean clock)
    {
      if(clock==true)
        this.clock = 1;
     
      else if(clock==true)
        this.clock =0;
        //this.clock = (byte)((clock) ? 1 : 0);
    }

    public boolean getClock()
    {
        return (clock == 1);
    }

    /**
     * setColor
     * True hvis billedet skal være i farver
     * False hvis det skal være Sort/hvid
     *
     * @param color boolean
     */
    public void setColor(boolean color)
    {
      if(color==true)
        this.clock = 1;
      else if(color==true)
        this.color = 0;
        //this.color = (byte)((color) ? 1 : 0);
    }

    public boolean getColor()
    {
        return (color == 1);
    }

    /**
     * setResolution
     * der er 4 formater:
     * 160x120
     * 320x240
     * 640x360
     * 640x480
     *
     * @param Resolution String
     */
    public void setResolution(String resolution)
    {
        this.resolution = resolution;
    }

    public String getResolution()
    {
        return resolution;
    }

    /**
     * setCompression
     * hvor meget billdet skal komprimeres i procent
     * et tal mellem 0 og 90
     *
     * @param compression short
     */
    public void setCompression(byte compression)
    {
        this.compression = compression;
    }

    public byte getCompression()
    {
        return compression;
    }

    public void setPath(String Path)
    {
        path = Path;
    }

    public String getPath()
    {
        return path;
    }

    public void setIP(String IP)
    {
        this.ip = IP;
    }

    public String getIP()
    {
        return ip;
    }

    /**
     * getimage
     * tag et billdede
     *
     * @return BufferedImage
     * @throws MalformedURLException
     */
    public BufferedImage getImage()
        throws MalformedURLException
    {
        String addr = "http://" + ip + "/" + path + "?";
        addr += param[0] + "=" + resolution + "&";
        addr += param[1] + "=" + compression + "&";
        addr += param[2] + "=" + color + "&";
        addr += param[3] + "=" + clock + "&";
        addr += param[4] + "=" + date;

        URL url = new URL(addr);

        try
        {
            BufferedImage img = ImageIO.read(url);
            ImageIO.write(img,"jpg", getNextFile());
            return img;
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
   
    public File getNextFile() {
    int i = 1;
    File file = new File("c:\\");

    while (file.exists()) {
      i++;
      file = new File("c:\\");
    }
   String f = file.getName();
    return file;
  }

   
    public static void main (String args[])
    {
      Webcamera webcam = new Webcamera();
     
     
    }
}
0
Comment
Question by:Maggieshah
1 Comment
 
LVL 14

Accepted Solution

by:
hoomanv earned 1000 total points
ID: 16657549
public File getNextFile() {
      int i = 1;
      File file = new File("c:\\img" + i + ".jpg");

      while (file.exists()) {
            i++;
            file = new File("c:\\img" + i + ".jpg");
      }
      String f = file.getName();
      return file;
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question