diff --git a/FaceCropper-library/src/main/java/cat/lafosca/facecropper/FaceCropper.java b/FaceCropper-library/src/main/java/cat/lafosca/facecropper/FaceCropper.java index b9ae59b..652808c 100644 --- a/FaceCropper-library/src/main/java/cat/lafosca/facecropper/FaceCropper.java +++ b/FaceCropper-library/src/main/java/cat/lafosca/facecropper/FaceCropper.java @@ -77,6 +77,10 @@ public void setFaceMarginPx(int faceMarginPx) { mSizeMode = SizeMode.FaceMarginPx; } + public SizeMode getSizeMode() { + return mSizeMode; + } + public float getEyeDistanceFactorMargin() { return mEyeDistanceFactorMargin; } diff --git a/FaceCropper-sample/src/main/java/cat/lafosca/facecropper/sample/MainActivity.java b/FaceCropper-sample/src/main/java/cat/lafosca/facecropper/sample/MainActivity.java index 03b2087..db7d258 100644 --- a/FaceCropper-sample/src/main/java/cat/lafosca/facecropper/sample/MainActivity.java +++ b/FaceCropper-sample/src/main/java/cat/lafosca/facecropper/sample/MainActivity.java @@ -10,7 +10,6 @@ import android.widget.ImageView; import android.widget.SeekBar; -import com.squareup.picasso.LruCache; import com.squareup.picasso.Picasso; import com.squareup.picasso.Transformation; @@ -21,7 +20,7 @@ public class MainActivity extends ActionBarActivity { private Picasso mPicasso; private FaceCropper mFaceCropper; private ViewPager mViewPager; - private LruCache mCache; + private Transformation mCropTransformation = new Transformation() { @Override @@ -31,7 +30,20 @@ public Bitmap transform(Bitmap source) { @Override public String key() { - return "crop()"; + StringBuilder builder = new StringBuilder(48); + + builder.append("faceCrop("); + builder.append("minSize=").append(mFaceCropper.getFaceMinSize()); + builder.append(",maxFaces=").append(mFaceCropper.getMaxFaces()); + + FaceCropper.SizeMode mode = mFaceCropper.getSizeMode(); + if (FaceCropper.SizeMode.EyeDistanceFactorMargin.equals(mode)) { + builder.append(",distFactor=").append(mFaceCropper.getEyeDistanceFactorMargin()); + } else if (FaceCropper.SizeMode.FaceMarginPx.equals(mode)) { + builder.append(",margin=").append(mFaceCropper.getFaceMarginPx()); + } + + return builder.append(")").toString(); } }; @@ -42,8 +54,7 @@ protected void onCreate(Bundle savedInstanceState) { mFaceCropper = new FaceCropper(1f); mFaceCropper.setFaceMinSize(0); - mCache = new LruCache(this); - mPicasso = new Picasso.Builder(this).memoryCache(mCache).build(); + mPicasso = Picasso.with(this); final ImageAdapter adapter = new ImageAdapter(); mViewPager = (ViewPager) findViewById(R.id.viewPager); @@ -68,7 +79,6 @@ public void onPageScrollStateChanged(int state) { seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { - mCache.clear(); mFaceCropper.setEyeDistanceFactorMargin((float) i / 10); adapter.updateView(mViewPager.getCurrentItem()); } @@ -126,7 +136,11 @@ public void setupView(View v, int position) { ImageView imageCropped = (ImageView) v.findViewById(R.id.imageViewCropped); mPicasso.load(urls[position]).into(image); - mPicasso.load(urls[position]).transform(mCropTransformation).into(imageCropped); + + mPicasso.load(urls[position]) + .config(Bitmap.Config.RGB_565) + .transform(mCropTransformation) + .into(imageCropped); } public void updateView(int position) {