private void saveOutput(Bitmap croppedImage) {
    if (saveUri != null) {
      OutputStream outputStream = null;
      try {
        outputStream = getContentResolver().openOutputStream(saveUri);
        if (outputStream != null) {
          croppedImage.compress(Bitmap.CompressFormat.JPEG, 90, outputStream);
        }
      } catch (IOException e) {
        setResultException(e);
        Log.e("Cannot open file: " + saveUri, e);
      } finally {
        CropUtil.closeSilently(outputStream);
      }

      CropUtil.copyExifRotation(
          CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri),
          CropUtil.getFromMediaUri(this, getContentResolver(), saveUri));

      setResultUri(saveUri);
    }

    final Bitmap b = croppedImage;
    handler.post(
        new Runnable() {
          public void run() {
            imageView.clear();
            b.recycle();
          }
        });

    finish();
  }
예제 #2
0
  private void saveOutput(Bitmap croppedImage) {
    if (saveUri != null) {
      OutputStream outputStream = null;
      try {
        outputStream = getContentResolver().openOutputStream(saveUri);
        if (outputStream != null) {

          if (exifRotation > 0) {
            try {
              Matrix matrix = new Matrix();
              matrix.reset();
              matrix.postRotate(exifRotation);
              Bitmap bMapRotate =
                  Bitmap.createBitmap(
                      croppedImage,
                      0,
                      0,
                      croppedImage.getWidth(),
                      croppedImage.getHeight(),
                      matrix,
                      true);
              bMapRotate.compress(Bitmap.CompressFormat.PNG, 70, outputStream);

            } catch (Exception e) {
              e.printStackTrace();
              croppedImage.compress(Bitmap.CompressFormat.PNG, 70, outputStream);
            } finally {
              if (croppedImage != null && !croppedImage.isRecycled()) {
                croppedImage.recycle();
              }
            }
          } else {
            croppedImage.compress(Bitmap.CompressFormat.PNG, 70, outputStream);
          }
        }

      } catch (IOException e) {
        setResultException(e);
        Log.e("Cannot open file: " + saveUri, e);
      } finally {
        CropUtil.closeSilently(outputStream);
      }

      if (!IN_MEMORY_CROP) {
        // In-memory crop negates the rotation
        CropUtil.copyExifRotation(
            CropUtil.getFromMediaUri(getContentResolver(), sourceUri),
            CropUtil.getFromMediaUri(getContentResolver(), saveUri));
      }

      setResultUri(saveUri);
    }

    final Bitmap b = croppedImage;
    handler.post(
        new Runnable() {

          public void run() {
            imageView.clear();
            b.recycle();
          }
        });

    finish();
  }