Пример #1
0
  private void startCrop() {
    if (isFinishing()) {
      return;
    }
    imageView.setImageRotateBitmapResetBase(rotateBitmap, true);
    CropUtil.startBackgroundJob(
        this,
        null,
        getResources().getString(R.string.crop__wait),
        new Runnable() {

          public void run() {
            final CountDownLatch latch = new CountDownLatch(1);
            handler.post(
                new Runnable() {

                  public void run() {
                    if (imageView.getScale() == 1F) {
                      imageView.center(true, true);
                    }
                    latch.countDown();
                  }
                });
            try {
              latch.await();
            } catch (InterruptedException e) {
              throw new RuntimeException(e);
            }
            new Cropper().crop();
          }
        },
        handler);
  }
Пример #2
0
  /*
   * TODO This should use the decode/crop/encode single step API so that the whole (possibly large) Bitmap doesn't need to be read
   * into memory
   */
  private void onSaveClicked() {
    if (cropView == null || isSaving) {
      return;
    }
    isSaving = true;

    Bitmap croppedImage = null;
    Rect r = cropView.getScaledCropRect(sampleSize);
    int width = r.width();
    int height = r.height();

    int outWidth = width, outHeight = height;
    if (maxX > 0 && maxY > 0 && (width > maxX || height > maxY)) {
      float ratio = (float) width / (float) height;
      if ((float) maxX / (float) maxY > ratio) {
        outHeight = maxY;
        outWidth = (int) ((float) maxY * ratio + .5f);
      } else {
        outWidth = maxX;
        outHeight = (int) ((float) maxX / ratio + .5f);
      }
    }

    if (IN_MEMORY_CROP && rotateBitmap != null) {
      croppedImage =
          inMemoryCrop(rotateBitmap, croppedImage, r, width, height, outWidth, outHeight);
      if (croppedImage != null) {
        imageView.setImageBitmapResetBase(croppedImage, true);
        imageView.center(true, true);
        imageView.highlightViews.clear();
      }
    } else {
      try {
        croppedImage = decodeRegionCrop(croppedImage, r);
        if (isCircleCrop) {
          croppedImage = cropCircleView(croppedImage);
        }
      } catch (IllegalArgumentException e) {
        setResultException(e);
        finish();
        return;
      }

      if (croppedImage != null) {
        imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true);
        imageView.center(true, true);
        imageView.highlightViews.clear();
      }
    }
    saveImage(croppedImage);
  }