2 Replies Latest reply: May 31, 2010 8:35 AM by 843802 RSS

    how to read an image from a url every 60 sec

    843802
      Hello!

      Im trying to find how to load(read) and save an image from a url every minute...Does anyone know how I can do this?


      thanx in advance for your vital answers!
      Joan
        • 1. Re: how to read an image from a url every 60 sec
          MSC
          Hi , Try this may help you


          package LiveWebCam;
          
          //www.AliJamali.com 
          
          import java.awt.Graphics;
          import java.awt.Image;
          import java.net.URL;
          import java.net.URLConnection;
          import javax.imageio.ImageIO;
          import javax.swing.JApplet;
          
          public class LiveWebCamNormalMotionJEPG extends JApplet
          implements MouseListener, MouseMotionListener
          {
          
          private Image mImg;
          private URL imageURL;
          private int x=0,y=0,mx=0, my=0;
          private boolean isMouseDraggingBox;
          private URLConnection urlConnection;
          boolean Active=true;
          
              class MyThread extends Thread
              {
                  public void run()
                  {
                      if(Thread.currentThread().getName().equals("T1"))
                          while(true) 
                          {
                              try
                              {
                                 imageURL = new URL("http://192.168.11.92/cgi-bin/image.jpg?display_mode=panorama&textdisplay=disable&quality=50");
                                  urlConnection = imageURL.openConnection();
                                  urlConnection.setDefaultUseCaches(false);
                                  urlConnection.setRequestProperty("Cache-Control", "no-store,max-age=0,no-cache");
                                  urlConnection.setRequestProperty("Expires", "0");
                                  urlConnection.setRequestProperty("Pragma", "no-cache");
                                  mImg = ImageIO.read(imageURL);
                                  if(Active)
                                      Active = false;
                                  repaint();
                              }
                              catch(Exception e)
                              {
                                  System.out.println("Problem in doBackground getting in loading : " + e.toString());
                              }
                              try
                              {
                                  sleep(1000L);
                              }
                              catch(InterruptedException e)
                              {
                                  e.printStackTrace();
                              }
                          }
                  }
                  MyThread(String n)
                  {
                      super(n);
                  }
              }
          
              public void init()
              {
                  MyThread t = new MyThread("T1");
                  t.start();
              }
          
              public void paint(Graphics g)
              {
                  if(Active)
                  {
                      g.drawString("Loading ........ ", 210, 150);
                  }
                  g.drawImage(mImg, x, y, 1400, 400, this);
                  repaint();
              }
          
              public void update(Graphics g)
              {
                  paint(g);
              }
          
          }
          • 2. Re: how to read an image from a url every 60 sec
            843802
            Finally I used a delay!
             try
                    {
                    Thread.sleep(60000);
                    }catch (InterruptedException ie)
                    {
                    System.out.println(ie.getMessage());
                    }