@Override
    protected File doInBackground(ImageFile... params) {
      Log.i(TAG, "------------------ start compress file ------------------");

      ImageFile srcFileInfo = params[0];

      Bitmap.CompressFormat format = mCompressFormat;
      if (format == null) {
        format = CompressFormatUtils.parseFormat(srcFileInfo.mSrcFilePath);
      }
      Log.i(TAG, "use compress format:" + format.name());

      File outputFile =
          CommonUtils.generateExternalImageCacheFile(mContext, CompressFormatUtils.getExt(format));
      File srcFile = new File(srcFileInfo.mSrcFilePath);
      boolean isCompress =
          compressImageFile(
              srcFileInfo.mSrcFilePath,
              outputFile.getPath(),
              mMaxWidth,
              mMaxHeight,
              mQuality,
              format);
      if (!isCompress) {
        // 没有压缩,直接copy
        CommonUtils.copy(srcFile, outputFile);
      }
      if (srcFileInfo.mDeleteSrc) {
        srcFile.delete();
      }
      return outputFile;
    }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mContentResolver = getContentResolver();

    setContentView(getContentViewId());

    mImageView = getCropImageView();

    // Work-around for devices incapable of using hardware-accelerated clipPath.
    // (android.view.GLES20Canvas.clipPath)
    //
    // See also:
    // - https://code.google.com/p/android/issues/detail?id=20474
    // - https://github.com/lvillani/android-cropimage/issues/20
    //
    if (Build.VERSION.SDK_INT > 10
        && Build.VERSION.SDK_INT < 16) { // >= Gingerbread && < Jelly Bean
      mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    if (extras != null) {
      if (extras.getBoolean("circleCrop", false)) {
        mCircleCrop = true;
        mAspectX = 1;
        mAspectY = 1;
        mOutputFormat = Bitmap.CompressFormat.PNG;
      }
      mSaveUri = (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT);
      if (mSaveUri != null) {
        String outputFormatString = extras.getString("outputFormat");
        if (outputFormatString != null) {
          mOutputFormat = Bitmap.CompressFormat.valueOf(outputFormatString);
        }
        mOutputQuality = extras.getInt("outputQuality", 100);
      } else {
        mSetWallpaper = extras.getBoolean("setWallpaper");
      }
      mBitmap = (Bitmap) extras.getParcelable("data");
      mAspectX = extras.getInt("aspectX");
      mAspectY = extras.getInt("aspectY");
      mOutputX = extras.getInt("outputX");
      mOutputY = extras.getInt("outputY");
      mOutlineColor = extras.getInt("outlineColor", HighlightView.DEFAULT_OUTLINE_COLOR);
      mOutlineCircleColor =
          extras.getInt("outlineCircleColor", HighlightView.DEFAULT_OUTLINE_CIRCLE_COLOR);
      mScale = extras.getBoolean("scale", true);
      mScaleUp = extras.getBoolean("scaleUpIfNeeded", true);
      mDoFaceDetection =
          extras.containsKey("noFaceDetection") ? !extras.getBoolean("noFaceDetection") : true;
    }

    if (mBitmap == null) {
      Uri target = intent.getData();
      mAllImages =
          ImageManager.makeImageList(mContentResolver, target, ImageManager.SORT_ASCENDING);
      mImage = mAllImages.getImageForUri(target);
      if (mImage != null) {
        // Don't read in really large bitmaps. Use the (big) thumbnail
        // instead.
        // TODO when saving the resulting bitmap use the
        // decode/crop/encode api so we don't lose any resolution.
        mBitmap = mImage.thumbBitmap(IImage.ROTATE_AS_NEEDED);
      }
    }

    if (mBitmap == null) {
      finish();
      return;
    }

    // Make UI fullscreen.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    Button discardButton = getDiscardButton();
    if (discardButton != null) {
      discardButton.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              setResult(RESULT_CANCELED);
              finish();
            }
          });
    }

    Button saveButton = getSaveButton();
    if (saveButton != null) {
      saveButton.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              onSaveClicked();
            }
          });
    }

    startFaceDetection();
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mContentResolver = getContentResolver();

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // MenuHelper.showStorageToast(this);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();

    if (extras != null) {
      // if (extras.getString("circleCrop") != null) {
      // mCircleCrop = true;
      // mAspectX = 1;
      // mAspectY = 1;
      // }
      mSaveUri = (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT);
      if (mSaveUri != null) {
        String outputFormatString = extras.getString("outputFormat");
        if (outputFormatString != null) {
          mOutputFormat = Bitmap.CompressFormat.valueOf(outputFormatString);
        }
      } else {
        mSetWallpaper = extras.getBoolean("setWallpaper");
      }
      mBitmap = (Bitmap) extras.getParcelable("data");
      mAspectX = extras.getInt("aspectX");
      mAspectY = extras.getInt("aspectY");
      mOutputX = extras.getInt("outputX");
      mOutputY = extras.getInt("outputY");
      mScale = extras.getBoolean("scale", false);
      mScaleUp = extras.getBoolean("scaleUpIfNeeded", false);
      // mDoFaceDetection = extras.containsKey("noFaceDetection")
      // ? !extras.getBoolean("noFaceDetection")
      // : true;

      android.content.res.Resources resources = getResources();
      int id = extras.getInt("arrowHorizontal", -1);
      if (id != -1) {
        mResizeDrawableWidth = resources.getDrawable(id);
      }
      id = extras.getInt("arrowVertical", -1);
      if (id != -1) {
        mResizeDrawableHeight = resources.getDrawable(id);
      }
      // id = extras.getInt("arrowDiagonal", -1);
      // if(id != -1){
      // mResizeDrawableDiagonal = resources.getDrawable(id);
      // }
    }

    if (mBitmap == null) {
      Uri target = intent.getData();
      try {
        decodeBitmapStreamSafe(target);
      } catch (OutOfMemoryError e) {
        OutOfMemoryHandler.handle();
      } catch (Throwable e) {
        e.printStackTrace();
      }
      // TODO
      // if (mImage != null) {
      // // Don't read in really large bitmaps. Use the (big) thumbnail
      // // instead.
      // // TODO when saving the resulting bitmap use the
      // // decode/crop/encode api so we don't lose any resolution.
      // mBitmap = mImage.thumbBitmap(IImage.ROTATE_AS_NEEDED);
      // }
    }

    if (mBitmap == null) {
      setResult(RESULT_CANCELED);
      finish();
      return;
    }

    // Make UI fullscreen.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.cropimage);

    mImageView = (CropImageView) findViewById(R.id.image);
    findViewById(R.id.discard)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                setResult(RESULT_CANCELED);
                finish();
              }
            });

    findViewById(R.id.crop)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                onSaveClicked();
              }
            });

    final Button btn = (Button) findViewById(R.id.no_crop);
    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // if (mNeedCrop)
            // {
            // mImageView.setImageBitmapResetBase(mBitmap, true);
            // mImageView.remove(mCrop);
            // mCrop = null;
            //
            // btn.setText(R.string.crop_text);
            // }
            // else
            // {
            // makeDefault();
            // mImageView.requestLayout();
            // mCrop = mImageView.mHighlightViews.get(0);
            // mCrop.setFocus(true);
            //
            // btn.setText(R.string.no_crop_text);
            // }
            // mNeedCrop = !mNeedCrop;
            mNeedCrop = false;
            onSaveClicked();
          }
        });

    // startFaceDetection();
    mImageView.setImageBitmapResetBase(mBitmap, true);
    makeDefault();
    mCrop = mImageView.mHighlightViews.get(0);
    mCrop.setFocus(true);
  }