@Override
  protected String doInBackground(String... arg0) {

    camera.startPreview();
    camera.takePicture(null, null, new PhotoHandler(mContext.getApplicationContext()));
    return "";
  }
 @Override
 public void onClick(View view) {
   if (mPreviewing) {
     mPreviewing = false;
     camera.takePicture(null, null, this);
   }
 }
Ejemplo n.º 3
0
 public void takePicture() {
   if (takePictureNow) {
     Log.d("HAA", "requesting picture");
     camera.takePicture(null, null, pictureReceiver);
   }
   Log.d("HAA", "picture task called");
 }
Ejemplo n.º 4
0
 public void takeCroppedPicture(final CroppedPictureCallback callback) {
   if (!opened) throw new IllegalStateException("Camera not opened yet");
   final Camera.PictureCallback pictureCallback =
       new Camera.PictureCallback() {
         @Override
         public void onPictureTaken(byte[] data, Camera cam) {
           previewing = false;
           int pictureWidth, pictureHeight;
           if (cameraRotation == 90 || cameraRotation == 270) {
             pictureWidth = pictureSize.height;
             pictureHeight = pictureSize.width;
           } else {
             pictureWidth = pictureSize.width;
             pictureHeight = pictureSize.height;
           }
           if (CROP_PREVIEW) { // The preview was cropped
             double scaleFactor, widthOffset, heightOffset;
             if (layoutWidth * pictureHeight > layoutHeight * pictureWidth) {
               scaleFactor = (double) pictureWidth / (double) layoutWidth;
               widthOffset = 0;
               heightOffset = (pictureHeight - layoutHeight * scaleFactor) / 2;
             } else {
               scaleFactor = (double) pictureHeight / (double) layoutHeight;
               widthOffset = (pictureWidth - layoutWidth * scaleFactor) / 2;
               heightOffset = 0;
             }
             callback.onPictureCropped(
                 Image.fromCroppedData(
                     data,
                     cameraRotation,
                     (int) (Edge.LEFT.getCoordinate() * scaleFactor + widthOffset),
                     (int) (Edge.TOP.getCoordinate() * scaleFactor + heightOffset),
                     (int) (Edge.getWidth() * scaleFactor),
                     (int) (Edge.getHeight() * scaleFactor)));
           } else { // The preview was stretched
             final double scaleFactorHorizontal = (double) pictureWidth / (double) layoutWidth;
             final double scaleFactorVertical = (double) pictureHeight / (double) layoutHeight;
             callback.onPictureCropped(
                 Image.fromCroppedData(
                     data,
                     cameraRotation,
                     (int) (Edge.LEFT.getCoordinate() * scaleFactorHorizontal),
                     (int) (Edge.TOP.getCoordinate() * scaleFactorVertical),
                     (int) (Edge.getWidth() * scaleFactorHorizontal),
                     (int) (Edge.getHeight() * scaleFactorVertical)));
           }
         }
       };
   final Camera.AutoFocusCallback autoFocusCallback =
       new Camera.AutoFocusCallback() {
         @Override
         public void onAutoFocus(boolean success, Camera cam) {
           camera.takePicture(null, null, pictureCallback);
         }
       };
   joinPreviewStarter();
   if (autofocus) camera.autoFocus(autoFocusCallback);
   else camera.takePicture(null, null, pictureCallback);
 }
Ejemplo n.º 5
0
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_CAMERA) {
     if (mCamera != null) {
       mCamera.takePicture(null, null, pic);
     }
   }
   return super.onKeyDown(keyCode, event);
 }
  public void take_picture() throws InterruptedException {
    camera.takePicture(shutter_callback, null, null, jpegCallback);

    synchronized (semaphore) {
      semaphore.wait();
    }

    camera.startPreview();
  }
Ejemplo n.º 7
0
 @Override
 public void onAutoFocus(boolean success, Camera camera) {
   if (success) {
     // takePicture()方法需要传入三个监听器参数
     // 第一个监听器:当用户按下快门时激发该监听器
     // 第二个监听器:当相机获取原始照片时激发该监听器
     // 第三个监听器:当相机获取JPG照片时激发该监听器
     camera.takePicture(null, null, mPictureCallback);
   }
 }
Ejemplo n.º 8
0
  @Override
  protected void captureFromCamera() {
    Toast.makeText(super.activity, "capture.", Toast.LENGTH_SHORT).show();
    camera.takePicture(null, null, mPicture);
    try {
      LogUtil.print("no of times = " + CheeseSpeechRecognizor.noOftimesRecognized);

    } catch (Exception e) {
      LogUtil.print(e.getMessage());
    }
  }
 @Override
 public void onFinish() {
   if (safeToTakePicture) {
     if (camera != null) {
       countdownTV.setText(getString(R.string.smile));
       shootSound();
       camera.takePicture(null, null, mPicture);
       safeToTakePicture = false;
     }
   }
 }
 public void takePicture() {
   if (captureFileName.length() > 0) {
     mCamera.takePicture(
         new Camera.ShutterCallback() {
           @Override
           public void onShutter() {}
         },
         callbackRAW,
         callbackImage);
   }
 }
Ejemplo n.º 11
0
 /** 按下快门一瞬间 */
 @Override
 public void capture() {
   if (mCamera != null) {
     // 控制摄像头自动对焦后才拍照,仅限于后置摄像头
     if (mCameraType == 0) {
       mCamera.autoFocus(autoFocusCallback);
     }
     // 前置摄像头有可能没有自动对焦功能
     mCamera.takePicture(null, null, mPictureCallback);
   }
 }
 private void takePicture() {
   Log.d(TAG, "takePicture()");
   try {
     pictureUri = prepareImageFile(timeStampFormat.format(new Date()), "Android Camera Image");
     Log.d(TAG, "picture uri: " + pictureUri.getPath());
     camera.takePicture(mShutterCallback, mPictureCallbackRaw, mPictureCallbackJpeg);
   } catch (Exception ex) {
     Log.e(TAG, "takePicture() exception caught: " + ex);
     saveResult(RESULT_CANCELED);
   }
 };
Ejemplo n.º 13
0
 /**
  * Initiates taking a picture, which happens asynchronously. The camera source should have been
  * activated previously with {@link #start()} or {@link #start(SurfaceHolder)}. The camera preview
  * is suspended while the picture is being taken, but will resume once picture taking is done.
  *
  * @param shutter the callback for image capture moment, or null
  * @param jpeg the callback for JPEG image data, or null
  */
 public void takePicture(ShutterCallback shutter, PictureCallback jpeg) {
   synchronized (mCameraLock) {
     if (mCamera != null) {
       PictureStartCallback startCallback = new PictureStartCallback();
       startCallback.mDelegate = shutter;
       PictureDoneCallback doneCallback = new PictureDoneCallback();
       doneCallback.mDelegate = jpeg;
       mCamera.takePicture(startCallback, null, null, doneCallback);
     }
   }
 }
Ejemplo n.º 14
0
 public void takePicture() {
   cam.takePicture(
       null,
       null,
       new Camera.PictureCallback() {
         @Override
         public void onPictureTaken(byte[] bytes, Camera camera) {
           Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
           ImagesIO.writeImage(activity, bmp, Integer.parseInt(devicearraydata[2]));
         }
       });
 }
Ejemplo n.º 15
0
 /** Take picture. */
 private void takePicture() {
   notTakingPic = false;
   try {
     // Try to auto-focus
     mCamera.autoFocus(onFocus);
   } catch (RuntimeException e) {
     e.printStackTrace();
     // If auto-focus didn't work, call the take picture method using the
     // jpegCallback variable
     mCamera.takePicture(null, null, jpegCallback);
   }
 }
  @Override
  public void onPictureTaken(byte[] data, Camera camera) {

    File pictureFileDir = getDir();

    if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {

      Log.d(DEBUG_TAG, "Can't create directory to save image.");
      mToast.setText("Can't create directory to save image.");
      mToast.show();
      return;
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
    String date = dateFormat.format(new Date());
    String photoFile = "Picture_" + date + "_" + photoCounter + ".jpg";

    String filename = pictureFileDir.getPath() + File.separator + photoFile;

    double lat = 0;
    double lon = 0;

    gpsHelper.getMyLocation();

    if (gpsHelper.isGPSenabled()) {
      lat = gpsHelper.getLatitude();
      lon = gpsHelper.getLongitude();

      String debugGps = String.valueOf(lat) + " " + String.valueOf(lon);
      this.tv.setText(debugGps);
      Log.d(DEBUG_TAG, debugGps);
      mToast.setText(debugGps);
      mToast.show();
    } else {
      Log.d(DEBUG_TAG, "GPS is not enabled.");
      mToast.setText("GPS is not enabled.");
      mToast.show();
    }

    (new WriteToFileTask(data, filename, lat, lon)).execute();

    photoCounter++;
    if (photoCounter < quantityPerStep) {
      camera.startPreview();
      camera.takePicture(null, null, this);
    } else {
      photoCounter = 0;
    }
    camera.startPreview();
  }
Ejemplo n.º 17
0
 public void capturePhoto() throws Exception {
   if (autoFocusEnabled) {
     mCamera.autoFocus(
         new Camera.AutoFocusCallback() {
           @Override
           public void onAutoFocus(boolean success, Camera camera) {
             if (success) mCamera.takePicture(null, null, mPicture);
           }
         });
   } else {
     mCamera.takePicture(null, null, mPicture);
   }
   // mCamera.takePicture(null, null, mPicture);
 }
Ejemplo n.º 18
0
  private void takePicture() {
    Camera.PictureCallback jpegCallback;
    final Context ctx = this;
    jpegCallback =
        new Camera.PictureCallback() {

          public void onPictureTaken(byte[] data, Camera camera) {
            System.out.println("data length=" + data.length);
            System.out.println("data=" + data);
            final ProgressDialog aDialog = ProgressDialog.show(ctx, "Camera action", "starting...");
            final Handler aHandler = new Handler();
            new Thread(
                    new Runnable() {
                      public void run() {
                        //						String url="http://10.0.2.2:8080/iCampServ/storebytes";
                        //						HttpClient httpClient=new DefaultHttpClient();
                        //						HttpPost httppost = new HttpPost(URI.create(url));
                        //						ByteArrayEntity be;
                        //						be = new ByteArrayEntity(data);
                        //						httppost.setEntity(be);
                        //						BasicHttpResponse httpResponse;
                        //						try {
                        //							httpResponse = (BasicHttpResponse) httpClient.execute(httppost);
                        //							System.out.println("status="+httpResponse.getStatusLine());
                        //						} catch (ClientProtocolException e) {
                        //							e.printStackTrace();
                        //						} catch (IOException e) {
                        //							e.printStackTrace();
                        //						} finally {
                        //							httpClient.getConnectionManager().closeExpiredConnections();
                        //						}

                        aDialog.dismiss();
                        System.out.println("Take pic and send to server ... done");
                        aHandler.post(
                            new Runnable() {
                              public void run() {
                                finishActivity();
                              }
                            });
                      }
                    })
                .start();
          }
        };
    mCamera.takePicture(null, null, jpegCallback);
  }
Ejemplo n.º 19
0
 public void takePicture() {
   int id = getFrontCameraId();
   if (id == -1) {
     Log.w(TAG, "No front camera available");
     return;
   }
   try {
     Log.d(TAG, "trying id" + id);
     mCamera = Camera.open(id);
     setCameraDisplayOrientation(mContext, id, mCamera);
     mCamera.startPreview();
     mCamera.autoFocus(null);
     mCamera.takePicture(null, null, null, new PictureSaver(mContext));
   } catch (Exception e) {
     Log.w(TAG, "Failed to take picture", e);
     close();
   }
 }
Ejemplo n.º 20
0
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    if (_camera == null) return;

    // stopPreview() will crash if preview is not running
    if (_isPreviewRunning) {
      _camera.stopPreview();
    }

    try {
      _camera.setPreviewDisplay(holder);
    } catch (IOException e) {
      Log.e(TAG, "Failed to set up preview", e);
    }
    _camera.startPreview();
    _isPreviewRunning = true;

    // Take the actual picture
    _camera.takePicture(null, null, mJpegPictureCallback);
  }
 /**
  * Listener for on screen clicks. Workaround for bug in 2.3.X: we stop the preview and start a new
  * one against a null surface Then take the picture.
  */
 public void onClick(View v) {
   if ((mCamera != null) && (!mCapturing)) {
     mCapturing = true;
     mCamera.stopPreview();
     mCamera.setPreviewCallback(null);
     Parameters params = mCamera.getParameters();
     Size defaultSize = params.getSupportedPictureSizes().get(0);
     int[] size = PanoCamera.getCameraSize(mContext, defaultSize.width, defaultSize.height);
     Log.d("OpenCV_Base", "Size is " + size[0] + "x" + size[1]);
     params.setPictureSize(size[0], size[1]);
     mCamera.setParameters(params);
     try {
       mCamera.setPreviewDisplay(null);
       mCamera.startPreview();
       mCamera.takePicture(null, null, jpegCallback);
     } catch (IOException e) {
       // Camera is unavailable, don't take a picture
       // TODO: alert user
     }
   }
 }
 public synchronized void takePhoto(View v) {
   System.out.println("take photo - " + cameraBusy);
   if (cameraBusy) return;
   if (!videoState) {
     cameraBusy = true;
     mCamera.takePicture(mShutter, null, mPicture);
   } else {
     if (!recording) {
       startRecording();
       takePhoto.setImageResource(R.drawable.stop);
       switchMode.setVisibility(View.INVISIBLE);
       zoomIn.setVisibility(View.INVISIBLE);
       zoomOut.setVisibility(View.INVISIBLE);
     } else {
       stopRecording();
       takePhoto.setImageResource(R.drawable.record);
       switchMode.setVisibility(View.VISIBLE);
       zoomIn.setVisibility(View.VISIBLE);
       zoomOut.setVisibility(View.VISIBLE);
     }
   }
 }
Ejemplo n.º 23
0
  @Override
  public boolean onBroadcast(int arg1, int arg2) {
    if (arg1 == PluginManager.MSG_NEXT_FRAME) {
      Camera camera = MainScreen.thiz.getCamera();
      if (camera != null) {
        // play tick sound
        MainScreen.guiManager.showCaptureIndication();
        MainScreen.thiz.PlayShutter();

        try {
          camera.setPreviewCallback(null);
          camera.takePicture(null, null, null, MainScreen.thiz);
        } catch (Exception e) {
          e.printStackTrace();
          Log.e("MainScreen takePicture() failed", "takePicture: " + e.getMessage());
          inCapture = false;
          takingAlready = false;
          Message msg = new Message();
          msg.arg1 = PluginManager.MSG_CONTROL_UNLOCKED;
          msg.what = PluginManager.MSG_BROADCAST;
          MainScreen.H.sendMessage(msg);
          MainScreen.guiManager.lockControls = false;
        }
      } else {
        inCapture = false;
        takingAlready = false;
        Message msg = new Message();
        msg.arg1 = PluginManager.MSG_CONTROL_UNLOCKED;
        msg.what = PluginManager.MSG_BROADCAST;
        MainScreen.H.sendMessage(msg);

        MainScreen.guiManager.lockControls = false;
      }
      return true;
    }
    return false;
  }
  /** Handle message/payload data from the FT3D server; implemented from the interface */
  @Override
  public void handleServerMessage(String message, String payload) {
    if (message.equals(BuildConfig.pic_registerResponse)) {
      _picRegisterButton.setText("Registered!");
      _picRegisterButton.setEnabled(false);

      _submitPicOrderButton.setText("Waiting for master...");
    } else if (message.equals(BuildConfig.pic_serverOrderingStart)) {
      _submitPicOrderButton.setEnabled(true);
      _submitPicOrderButton.setText("Submit Order");
    } else if (message.equals(BuildConfig.pic_frameOrderResponse)) {
      _picFrameNumber = Integer.valueOf(payload);
      _picReadyButton.setEnabled(true);

      _submitPicOrderButton.setText("Frame Number: " + _picFrameNumber);
      _submitPicOrderButton.setEnabled(false);
    } else if (message.equals(BuildConfig.pic_takeFramePic)) {
      if (_systemCamera != null) {
        _systemCamera.takePicture(null, null, _pictureCallback);
      }
    } else if (message.equals(BuildConfig.pic_resetPicTaker)) {
      resetPicTaker();
    }
  }
Ejemplo n.º 25
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.takePhotoButton) {
      camera.takePicture(shutterCallback, rawCallback, jpegCallback);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.INVISIBLE);
    }
    if (v.getId() == R.id.cameraTryAgainButton) {
      Button saveButton = (Button) findViewById(R.id.savePhotoButton);
      saveButton.setVisibility(View.INVISIBLE);
      Button cameraTryAgainButton = (Button) findViewById(R.id.cameraTryAgainButton);
      cameraTryAgainButton.setVisibility(View.INVISIBLE);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.VISIBLE);
      camera.startPreview();
      /*canvas = holder.lockCanvas();
      Picture picture = new Picture();
      picture.draw(canvas);
      canvas.drawPicture(picture);
      holder.unlockCanvasAndPost(canvas);*/
    }
    if (v.getId() == R.id.savePhotoButton) {
      filename = "picture" + ic.numberOfPictures + ".jpg"; // STEP ONE : Set filename
      ic.numberOfPictures++;
      file = path + filename;

      Calendar calendar = new GregorianCalendar(); // STEP TWO : Get Calendar object
      int month = calendar.get(calendar.MONTH); // 			  and time/date
      int day = calendar.get(calendar.DAY_OF_MONTH);
      String time = calendar.getTime().toString().substring(11, 19);
      int hour = Integer.valueOf(time.substring(0, 2));
      if (hour > 12) {
        int oldHour = hour; // STEP THREE: Format time
        hour = hour - 12;
        String oldS = Integer.toString(oldHour);
        String hourS = Integer.toString(hour);
        if (hourS.length() == 1) hourS = "0" + hourS;
        time = time.substring(2);
        time = hourS + time;
        time.replaceFirst(oldS, hourS);
        isAM = false;
      }
      if (isAM) time = time + " AM " + " ---		Picture";
      else time = time + " PM " + " ---		Picture";
      String year = new Integer(calendar.get(calendar.YEAR)).toString();
      database
          .get(year)
          .get(months[month])
          .get(days[day - 1])
          .put(time, file); // STEP FOUR: Pull day out of
      Toast.makeText(this, "Picture saved to: " + file, Toast.LENGTH_LONG)
          .show(); //			  the database
      Button saveButton = (Button) findViewById(R.id.savePhotoButton);
      saveButton.setVisibility(View.INVISIBLE);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.INVISIBLE);
      try {
        FileOutputStream camFOS =
            new FileOutputStream(file); // STEP FIVE: Save picture to MindBook directory
        camFOS.write(picture);
        camFOS.close();
      } catch (FileNotFoundException fnfe) {
        Log.d("CAMERA", fnfe.getMessage());
      } catch (IOException ioe) {
        Log.d("CAMERA", ioe.getMessage());
      }
      try {
        ObjectOutputStream dataOOS =
            new ObjectOutputStream(new FileOutputStream(path + "database.ser"));
        dataOOS.writeObject(database);
        dataOOS.close();
        ObjectOutputStream counterOOS =
            new ObjectOutputStream(new FileOutputStream(path + "counter.ser"));
        counterOOS.writeObject(ic);
        counterOOS.close();
      } catch (Exception e) {
        Log.d("CAMERA", e.getMessage());
      }
    }
  }
Ejemplo n.º 26
0
 public void SnapIt(View view) {
   cameraObject.takePicture(null, null, capturedIt);
 }
  private void takeImage() {
    camera.takePicture(
        null,
        null,
        new PictureCallback() {

          private File imageFile;

          @Override
          public void onPictureTaken(byte[] data, Camera camera) {
            try {
              // convert byte array into bitmap
              Bitmap loadedImage = null;
              Bitmap rotatedBitmap = null;
              loadedImage = BitmapFactory.decodeByteArray(data, 0, data.length);

              // rotate Image
              Matrix rotateMatrix = new Matrix();
              rotateMatrix.postRotate(rotation);
              rotatedBitmap =
                  Bitmap.createBitmap(
                      loadedImage,
                      0,
                      0,
                      loadedImage.getWidth(),
                      loadedImage.getHeight(),
                      rotateMatrix,
                      false);
              String state = Environment.getExternalStorageState();
              File folder = null;
              if (state.contains(Environment.MEDIA_MOUNTED)) {
                folder = new File(Environment.getExternalStorageDirectory() + "/Demo");
              } else {
                folder = new File(Environment.getExternalStorageDirectory() + "/Demo");
              }

              boolean success = true;
              if (!folder.exists()) {
                success = folder.mkdirs();
              }
              if (success) {
                java.util.Date date = new java.util.Date();
                imageFile =
                    new File(
                        folder.getAbsolutePath()
                            + File.separator
                            + new Timestamp(date.getTime()).toString()
                            + "Image.jpg");

                imageFile.createNewFile();
              } else {
                Toast.makeText(getBaseContext(), "Image Not saved", Toast.LENGTH_SHORT).show();
                return;
              }

              ByteArrayOutputStream ostream = new ByteArrayOutputStream();

              // save image into gallery
              rotatedBitmap.compress(CompressFormat.JPEG, 100, ostream);

              FileOutputStream fout = new FileOutputStream(imageFile);
              fout.write(ostream.toByteArray());
              fout.close();
              ContentValues values = new ContentValues();

              values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
              values.put(Images.Media.MIME_TYPE, "image/jpeg");
              values.put(MediaStore.MediaColumns.DATA, imageFile.getAbsolutePath());

              MainActivity.this
                  .getContentResolver()
                  .insert(Images.Media.EXTERNAL_CONTENT_URI, values);

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }
Ejemplo n.º 28
0
 @Override
 public void onFocused(Camera camera) {
   camera.takePicture(null, rawPictureCallback, pictureCallback);
 }
Ejemplo n.º 29
0
 public void takePhoto() {
   Log.e(TAG, "take photo");
   camera.takePicture(null, null, new TakePictureCallback());
 }
Ejemplo n.º 30
0
 public void onAutoFocus(boolean success, Camera camera) {
   // Call the take picture method using the jpegCallback variable
   camera.takePicture(null, null, jpegCallback);
 }