package socket01;

public class camera
{
   private final String _raspistillPath = "/opt/vc/bin/raspistill";
   private final int Timeout = 1000;
   private final int Quality = 100;
   private int Width = 1024;
   private int Height = 768;
   private String Name = "example.jpg";
   private String Type = "jpg";

   // constructeur
   public void RaspiStill()
   {
      // rien pour l'instant
   }
  
   public void TakePicture()
   {
      try
      {
         if (Name.indexOf('.')!=-1)
        	 Type = Name.substring(Name.lastIndexOf('.')+1);

         StringBuilder sb = new StringBuilder(_raspistillPath);

         //  no preview et burst mode.
         sb.append(" -n -bm");
         //  timeout.
         sb.append(" -t " + Timeout);
         sb.append(" -w " + Width);
         sb.append(" -h " + Height);
         sb.append(" -q " + Quality);
         sb.append(" -e " + Type);
         sb.append(" -o " + Name);

         // commande pour prendre la photo
         Runtime.getRuntime().exec(sb.toString());
         // pause pour la prise de vue
         Thread.sleep(Timeout);
         
         //convert your_test_photo.jpg -font Arial -pointsize 72 -fill white -annotate +100+100  %[exif:DateTimeOriginal] output.jpg
         
      }
      catch (Exception e)
      {
         System.exit(e.hashCode());
      }
   }

   // surcharge
   public void TakePicture(String name, int width, int height)
   {
      Name = name;
      Width = width;
      Height = height;
      TakePicture();
   }

   // surcharge
   public void TakePicture(String name)
   {
      TakePicture(name, Width, Height);
   }

   // surcharge
   public void TakePicture(int width, int height)
   {
      TakePicture(Name, width, height);
   }
}