示例#1
0
        // Create a default HightlightView if we found no face in the picture.
        private void makeDefault() {

          HighlightView hv = new HighlightView(mImageView);

          int width = mBitmap.getWidth();
          int height = mBitmap.getHeight();

          Rect imageRect = new Rect(0, 0, width, height);

          // make the default size about 4/5 of the width or height
          int cropWidth = Math.min(width, height) * 4 / 5;
          int cropHeight = cropWidth;

          if (mAspectX != 0 && mAspectY != 0) {

            if (mAspectX > mAspectY) {

              cropHeight = cropWidth * mAspectY / mAspectX;
            } else {

              cropWidth = cropHeight * mAspectX / mAspectY;
            }
          }

          int x = (width - cropWidth) / 2;
          int y = (height - cropHeight) / 2;

          RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);
          hv.setup(mImageMatrix, imageRect, cropRect, mCircleCrop, mAspectX != 0 && mAspectY != 0);

          mImageView.mHighlightViews.clear(); // Thong added for rotate

          mImageView.add(hv);
        }
示例#2
0
  private void startFaceDetection() {

    if (isFinishing()) {
      return;
    }

    mImageView.setImageBitmapResetBase(mBitmap, true);

    Util.startBackgroundJob(
        this,
        null,
        "Please wait\u2026",
        new Runnable() {
          public void run() {

            final CountDownLatch latch = new CountDownLatch(1);
            final Bitmap b = mBitmap;
            mHandler.post(
                new Runnable() {
                  public void run() {

                    if (b != mBitmap && b != null) {
                      mImageView.setImageBitmapResetBase(b, true);
                      mBitmap.recycle();
                      mBitmap = b;
                    }
                    if (mImageView.getScale() == 1F) {
                      mImageView.center(true, true);
                    }
                    latch.countDown();
                  }
                });
            try {
              latch.await();
            } catch (InterruptedException e) {
              throw new RuntimeException(e);
            }
            mRunFaceDetection.run();
          }
        },
        mHandler);
  }
示例#3
0
        public void run() {

          mImageMatrix = mImageView.getImageMatrix();
          Bitmap faceBitmap = prepareBitmap();

          mScale = 1.0F / mScale;
          if (faceBitmap != null && mDoFaceDetection) {
            FaceDetector detector =
                new FaceDetector(faceBitmap.getWidth(), faceBitmap.getHeight(), mFaces.length);
            mNumFaces = detector.findFaces(faceBitmap, mFaces);
          }

          if (faceBitmap != null && faceBitmap != mBitmap) {
            faceBitmap.recycle();
          }

          mHandler.post(
              new Runnable() {
                public void run() {

                  mWaitingToPick = mNumFaces > 1;
                  if (mNumFaces > 0) {
                    for (int i = 0; i < mNumFaces; i++) {
                      handleFace(mFaces[i]);
                    }
                  } else {
                    makeDefault();
                  }
                  mImageView.invalidate();
                  if (mImageView.mHighlightViews.size() == 1) {
                    mCrop = mImageView.mHighlightViews.get(0);
                    mCrop.setFocus(true);
                  }

                  if (mNumFaces > 1) {
                    Toast.makeText(CropImage.this, "Multi face crop help", Toast.LENGTH_SHORT)
                        .show();
                  }
                }
              });
        }
示例#4
0
        // For each face, we create a HightlightView for it.
        private void handleFace(FaceDetector.Face f) {

          PointF midPoint = new PointF();

          int r = ((int) (f.eyesDistance() * mScale)) * 2;
          f.getMidPoint(midPoint);
          midPoint.x *= mScale;
          midPoint.y *= mScale;

          int midX = (int) midPoint.x;
          int midY = (int) midPoint.y;

          HighlightView hv = new HighlightView(mImageView);

          int width = mBitmap.getWidth();
          int height = mBitmap.getHeight();

          Rect imageRect = new Rect(0, 0, width, height);

          RectF faceRect = new RectF(midX, midY, midX, midY);
          faceRect.inset(-r, -r);
          if (faceRect.left < 0) {
            faceRect.inset(-faceRect.left, -faceRect.left);
          }

          if (faceRect.top < 0) {
            faceRect.inset(-faceRect.top, -faceRect.top);
          }

          if (faceRect.right > imageRect.right) {
            faceRect.inset(faceRect.right - imageRect.right, faceRect.right - imageRect.right);
          }

          if (faceRect.bottom > imageRect.bottom) {
            faceRect.inset(faceRect.bottom - imageRect.bottom, faceRect.bottom - imageRect.bottom);
          }

          hv.setup(mImageMatrix, imageRect, faceRect, mCircleCrop, mAspectX != 0 && mAspectY != 0);

          mImageView.add(hv);
        }