├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── vn │ │ └── nano │ │ └── photocropper │ │ └── photocropper │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── vn │ │ │ └── nano │ │ │ └── photocropper │ │ │ └── photocropper │ │ │ ├── MainActivity.java │ │ │ └── MyApplication.java │ └── res │ │ ├── drawable-xxxhdpi │ │ └── img_test.jpg │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── vn │ └── nano │ └── photocropper │ └── photocropper │ └── ExampleUnitTest.java ├── bintrayv1.gradle ├── build.gradle ├── demo.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── installv1.gradle ├── photo-cropper ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── vn │ │ └── nano │ │ └── photocropper │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── vn │ │ │ └── nano │ │ │ └── photocropper │ │ │ ├── CropImageView.java │ │ │ ├── CropListener.java │ │ │ ├── CropOverlayView.java │ │ │ └── CropPosition.java │ └── res │ │ ├── layout │ │ └── crop_image_view.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── vn │ └── nano │ └── photocropper │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | app/build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PhotoPolygonCropper 2 | ### Description 3 | Crop photo using polygon 4 | ### Usage 5 | 6 | 7 | 8 | - Add to `build.gradle` 9 | 10 | ``` 11 | compile 'vn.tinyhands:photo-cropper:0.0.8' 12 | ``` 13 | - Declare `CropImageView` in your layout 14 | ``` 15 | 20 | ``` 21 | - Set bitmap to crop 22 | ``` 23 | cropImageView.setImageBitmap(bitmap); 24 | ``` 25 | - Call `crop()` function to get cropped bitmap 26 | ``` 27 | cropImageView.crop(Croplistener cropListener, boolean needStretch); 28 | ```` 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion '27.0.3' 6 | defaultConfig { 7 | applicationId "vn.nano.photocropper.photocropper" 8 | minSdkVersion 16 9 | targetSdkVersion 27 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | compile 'com.android.support:appcompat-v7:27.+' 27 | }) 28 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | 31 | implementation 'com.jakewharton.timber:timber:4.6.0' 32 | 33 | compile project(path: ':photo-cropper') 34 | // compile 'vn.tinyhands:photo-cropper:0.0.6' 35 | } 36 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Volumes/AlexData/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/vn/nano/photocropper/photocropper/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package vn.nano.photocropper.photocropper; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("vn.nano.photocropper.photocropper", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/vn/nano/photocropper/photocropper/MainActivity.java: -------------------------------------------------------------------------------- 1 | package vn.nano.photocropper.photocropper; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.graphics.Matrix; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | import android.widget.ImageView; 10 | 11 | import vn.nano.photocropper.CropImageView; 12 | import vn.nano.photocropper.CropListener; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | Bitmap mBitmap; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | 23 | mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img_test); 24 | final CropImageView cropImageView = findViewById(R.id.crop_image_view); 25 | cropImageView.setImageBitmap(mBitmap); 26 | 27 | final CropListener listener = new CropListener() { 28 | @Override 29 | public void onFinish(Bitmap bitmap) { 30 | // cropImageView.setImageBitmap(bitmap); 31 | findViewById(R.id.crop_image_view).setVisibility(View.GONE); 32 | 33 | findViewById(R.id.img_cropped).setVisibility(View.VISIBLE); 34 | ((ImageView)findViewById(R.id.img_cropped)).setImageBitmap(bitmap); 35 | } 36 | }; 37 | 38 | findViewById(R.id.btn_crop).setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | cropImageView.crop(listener, true); 42 | } 43 | }); 44 | 45 | findViewById(R.id.btn_rotate).setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | rotateBitmap(); 49 | } 50 | }); 51 | } 52 | 53 | private void rotateBitmap() { 54 | Matrix matrix = new Matrix(); 55 | matrix.postRotate( 90); 56 | 57 | mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, false); 58 | ((CropImageView) findViewById(R.id.crop_image_view)).setImageBitmap(mBitmap); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/vn/nano/photocropper/photocropper/MyApplication.java: -------------------------------------------------------------------------------- 1 | package vn.nano.photocropper.photocropper; 2 | 3 | import android.app.Application; 4 | 5 | import timber.log.Timber; 6 | 7 | /** 8 | * Created by alex on 12/4/17. 9 | */ 10 | 11 | public class MyApplication extends Application { 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | Timber.plant(new Timber.DebugTree()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/img_test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanh215/Photo-Cropper/95c94e6a9cf48d2ce403f7da3fe720d300504262/app/src/main/res/drawable-xxxhdpi/img_test.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 17 | 18 | 22 | 23 | 29 | 30 | 31 | 32 | 39 | 40 |