├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── meitu
│ │ └── cropimageproject
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── ezgif.com-video-to-gif.gif
│ ├── java
│ │ └── com
│ │ │ └── meitu
│ │ │ └── cropimageproject
│ │ │ └── activity
│ │ │ ├── DisplayActivity.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_launcher.png
│ │ └── screenshot.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── display_iamge_activity.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
│ └── com
│ └── meitu
│ └── cropimageproject
│ └── ExampleUnitTest.java
├── build.gradle
├── cropimagelibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── meitu
│ │ └── cropimagelibrary
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── meitu
│ │ │ └── cropimagelibrary
│ │ │ ├── info
│ │ │ └── ImageInfo.java
│ │ │ ├── util
│ │ │ ├── FileUtil.java
│ │ │ ├── ImageLoadUtil.java
│ │ │ ├── RectUtils.java
│ │ │ ├── RotationGestureDetector.java
│ │ │ └── SaveBitmapCallback.java
│ │ │ └── view
│ │ │ └── CropImageView.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── meitu
│ └── cropimagelibrary
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | GitHub同步
4 | https://github.com/waterCode
5 |
6 | 博客地址:http://blog.csdn.net/sinat_28676875/article/details/60322063
7 |
8 | 动态图:
9 | 
10 |
11 | 用法:
12 | ```xml
13 |
19 | ```
20 | ```java
21 | CropImageView mNeedCropView = (CropImageView) findViewById(R.id.crop_photo_civ);
22 | uri = getIntent().getParcelableExtra("uri");
23 | mNeedCropView.setImageURI(uri);
24 | ```
25 | 用法大概和ImageView相同,不过要保存图片要申请权限,,6.0以上要动态申请,直接设置uri,我这里的uri是从图库里面选着返回的
26 |
27 | 其他public方法,
28 | ```java
29 | /**
30 | * 设置最小放大倍数
31 | *
32 | * @param MIN_SCALE 最小放大倍数
33 | */
34 | setMinScale(float MIN_SCALE)
35 | /**
36 | * 设置最小放大倍数
37 | *
38 | * @param MAX_SCALE 最大放大倍数
39 | */
40 | setMaxScale(float MAX_SCALE);
41 |
42 |
43 | /**
44 | * 放大设置开关
45 | *
46 | * @param mScaleEnable 是否开启
47 | */
48 | setScaleEnable(boolean mScaleEnable);
49 |
50 | /**
51 | * 旋转开关
52 | *
53 | * @param mRotateEnable 是否开启
54 | */
55 | setRotateEnable(boolean mRotateEnable);//设置是否开启旋转
56 |
57 | setHorizontalMirror();//设置是否开启水平镜像
58 | setVerticalMirror();//设置垂直镜像
59 | postAnyRotate(float anyAngel);//旋转图片任意角度,
60 | ```
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 24
6 | buildToolsVersion "26.0.1"
7 | defaultConfig {
8 | applicationId "com.meitu.cropimageproject"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 |
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:25.3.1'
31 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
32 | testCompile 'junit:junit:4.12'
33 | compile 'com.github.bumptech.glide:glide:3.8.0'
34 | compile 'com.android.support:support-v4:25.3.1'
35 | annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
36 | compile project(':cropimagelibrary')
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/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 C:\Users\meitu\AppData\Local\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/com/meitu/cropimageproject/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimageproject;
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("com.meitu.cropimageproject", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/assets/ezgif.com-video-to-gif.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/assets/ezgif.com-video-to-gif.gif
--------------------------------------------------------------------------------
/app/src/main/java/com/meitu/cropimageproject/activity/DisplayActivity.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimageproject.activity;
2 |
3 | import android.content.pm.PackageManager;
4 | import android.graphics.Bitmap;
5 | import android.media.MediaScannerConnection;
6 | import android.net.Uri;
7 | import android.os.AsyncTask;
8 | import android.os.Bundle;
9 | import android.os.Environment;
10 | import android.os.Handler;
11 | import android.os.Looper;
12 | import android.os.Message;
13 | import android.os.MessageQueue;
14 | import android.support.annotation.Nullable;
15 | import android.support.v4.app.ActivityCompat;
16 | import android.support.v4.content.ContextCompat;
17 | import android.support.v7.app.AppCompatActivity;
18 | import android.util.Log;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 |
22 | import com.meitu.cropimagelibrary.util.FileUtil;
23 | import com.meitu.cropimagelibrary.util.SaveBitmapCallback;
24 | import com.meitu.cropimagelibrary.view.CropImageView;
25 | import com.meitu.cropimageproject.R;
26 |
27 | import java.io.File;
28 |
29 |
30 | /**
31 | * Created by zmc on 2017/7/18.
32 | */
33 |
34 | public class DisplayActivity extends AppCompatActivity {
35 | private String TAG = "DisplayActivity";
36 | private Uri uri;//怎么部分重构?
37 | private CropImageView mNeedCropView;
38 | private Looper looper;
39 |
40 |
41 | private static class MyHandler extends Handler{
42 | @Override
43 | public void handleMessage(Message msg) {
44 | super.handleMessage(msg);
45 | //处理消息,
46 | }
47 | }
48 |
49 | private static class MyHanderCallback implements Handler.Callback{
50 |
51 | @Override
52 | public boolean handleMessage(Message msg) {
53 | return false;
54 | }
55 | }
56 | private Handler myHandler = new Handler(new MyHanderCallback());
57 |
58 | @Override
59 | protected void onCreate(@Nullable Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 | setContentView(R.layout.display_iamge_activity);
62 | Log.d(TAG,"maxmemory"+(Runtime.getRuntime().maxMemory()/1024/1024));
63 | if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
64 | != PackageManager.PERMISSION_GRANTED) {
65 | ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
66 | } else {
67 | //
68 | //finish();
69 | }
70 |
71 | mNeedCropView = (CropImageView) findViewById(R.id.crop_photo_civ);
72 | uri = getIntent().getParcelableExtra("uri");
73 | mNeedCropView.setImageURI(uri);
74 |
75 | }
76 |
77 | // TODO: 2017/7/27 Exif 方向
78 | // TODO: 2017/7/27 大尺寸图片oom ,不同阶段
79 | public void onClick(View v) {
80 | switch (v.getId()) {
81 | case R.id.set_mirror_image_bt:
82 | mNeedCropView.setHorizontalMirror();
83 | break;
84 | case R.id.crop_Image_bt:
85 |
86 |
87 | Bitmap bitmap = mNeedCropView.cropAndSaveImage();
88 | SaveFileTask saveFileTask = new SaveFileTask();
89 | saveFileTask.execute(bitmap);
90 | break;
91 | case R.id.rightRotate_bt:
92 | mNeedCropView.postAnyRotate(45);
93 | break;
94 | case R.id.leftRotate_bt:
95 | mNeedCropView.leftRotate90();
96 | break;
97 | case R.id.cancel_crop_activity_bt:
98 | finish();
99 | default:
100 | break;
101 | }
102 | }
103 |
104 |
105 | public File getDefaultDir() {
106 | File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "crop_iamge");
107 | if (!file.exists()) {
108 | file.mkdir();
109 | }
110 | return file;
111 | }
112 |
113 |
114 | private class SaveFileTask extends AsyncTask {
115 |
116 | @Override
117 | protected File doInBackground(Bitmap... params) {
118 |
119 | if (params == null && params.length < 1)
120 | return null;
121 | File parent = getDefaultDir();
122 | if(params[0] ==null)
123 | return null;
124 | return FileUtil.bitmapConvertToFile(DisplayActivity.this, params[0], parent, new SaveBitmapCallback() {
125 |
126 | @Override
127 | public void onFailed() {
128 |
129 | }
130 | });
131 | }
132 |
133 |
134 | @Override
135 | protected void onPostExecute(File file) {
136 | super.onPostExecute(file);
137 | if (file != null) {
138 | Log.d(TAG, "图片文件路径为" + file.getAbsolutePath());
139 | //通知图库
140 | MediaScannerConnection.scanFile(DisplayActivity.this, new String[]{file.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
141 |
142 |
143 | @Override
144 | public void onScanCompleted(String path, Uri uri) {
145 | Log.d(TAG, "扫描后 path"+ path+" uri :"+uri.toString());
146 |
147 | }
148 | });
149 | }
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/app/src/main/java/com/meitu/cropimageproject/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimageproject.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 |
10 | import com.meitu.cropimageproject.R;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | public static final int GET_IMAGE = 1;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 | }
22 |
23 |
24 | public void onClick(View v) {
25 | //就一个按钮
26 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
27 | intent.setType("image/*");
28 | startActivityForResult(intent, GET_IMAGE);
29 | }
30 |
31 | @Override
32 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
33 | super.onActivityResult(requestCode, resultCode, data);
34 | if (resultCode == Activity.RESULT_OK) {
35 | switch (requestCode) {
36 | case GET_IMAGE:
37 | Uri uri = data.getData();
38 | Intent intent = new Intent(this, DisplayActivity.class);
39 | intent.putExtra("uri", uri);
40 | startActivity(intent);
41 | break;
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/drawable/screenshot.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/display_iamge_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
14 |
19 |
20 |
27 |
28 |
35 |
36 |
43 |
50 |
51 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CropImageProject
3 | CropImageView
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/meitu/cropimageproject/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimageproject;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.0-beta4'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 |
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/cropimagelibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/cropimagelibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 |
25 |
26 |
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31 | exclude group: 'com.android.support', module: 'support-annotations'
32 | })
33 | compile 'com.android.support:appcompat-v7:24.2.1'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
--------------------------------------------------------------------------------
/cropimagelibrary/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 C:\Users\meitu\AppData\Local\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 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/androidTest/java/com/meitu/cropimagelibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary;
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("com.meitu.cropimagelibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/info/ImageInfo.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.info;
2 |
3 | /**
4 | * Created by zmc on 2017/7/19.
5 | */
6 |
7 | public class ImageInfo {
8 | private final float mInitWidth;
9 | private final float mInitHeight;
10 | private final float mInitScale;
11 |
12 | private float mGestureScale = 1;
13 |
14 | public ImageInfo(float mWidth, float mHeight, float mScale) {
15 | this.mInitWidth = mWidth;
16 | this.mInitHeight = mHeight;
17 | this.mInitScale = mScale;
18 | }
19 |
20 | public float getInitWidth() {
21 | return mInitWidth;
22 | }
23 |
24 | public float getInitHeight() {
25 | return mInitHeight;
26 | }
27 |
28 | public float getInitScale() {
29 | return mInitScale;
30 | }
31 |
32 | public float getGestureScale() {
33 | return mGestureScale;
34 | }
35 |
36 | public void setGestureScale(float mGestureScale) {
37 | this.mGestureScale = mGestureScale;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.os.Environment;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.util.Log;
9 |
10 | import java.io.File;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.text.SimpleDateFormat;
14 | import java.util.Calendar;
15 |
16 | /**
17 | * Created by zmc on 2017/7/24.
18 | */
19 |
20 | public class FileUtil {
21 |
22 |
23 | public static File bitmapConvertToFile(Context context, @NonNull Bitmap bitmap, File parent, final SaveBitmapCallback callback) {
24 |
25 | if (parent == null) {
26 | parent = createDefaultFolder(context, callback);
27 | }
28 |
29 | if (parent == null) return null;
30 | File bitmapFile = new File(parent, "IMG_" + (new SimpleDateFormat("yyyyMMddHHmmss")).format(Calendar.getInstance().getTime()) + ".jpg");
31 | FileOutputStream fileOutputStream = null;
32 | try {
33 | fileOutputStream = new FileOutputStream(bitmapFile);
34 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
35 | //通知本地扫描,这样可以让图库可以检测到
36 |
37 | } catch (IOException e) {
38 | e.printStackTrace();
39 | callback.onFailed();
40 | } finally {
41 | if (fileOutputStream != null) {
42 | try {
43 | fileOutputStream.close();
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | callback.onFailed();
47 | }
48 | }
49 | }
50 |
51 | return bitmapFile;
52 | }
53 |
54 | @Nullable
55 | private static File createDefaultFolder(Context context, SaveBitmapCallback callback) {
56 | File file = new File(context.getFilesDir(), "image_crop_sample");
57 | if (!file.exists()) {
58 | if (!file.mkdir()) {
59 | Log.e("FileUtil", "directory create failed");
60 | callback.onFailed();
61 | }
62 | }
63 | return file;
64 | }
65 |
66 |
67 | public static boolean isExternalStoageWriable() {
68 | String state = Environment.getExternalStorageState();
69 | if (Environment.MEDIA_MOUNTED.equals(state)) {
70 | return true;
71 | } else {
72 | return false;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/util/ImageLoadUtil.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.util;
2 |
3 | import android.content.ContentResolver;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Matrix;
7 | import android.graphics.Rect;
8 | import android.media.ExifInterface;
9 | import android.net.Uri;
10 | import android.util.Log;
11 |
12 | import java.io.FileNotFoundException;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 |
16 | /**
17 | * Created by zmc on 2017/7/19.
18 | */
19 |
20 | public class ImageLoadUtil {
21 | private static final String TAG = "ImageLoadUtil";
22 |
23 | /**
24 | * @param contentResolver 内容提供器
25 | * @param uri 图片的uri
26 | * @param maxHeight 最大高度
27 | * @param maxWidth 最大宽度
28 | * @return 对应的Bitmap对象
29 | * @throws FileNotFoundException
30 | */
31 | public static Bitmap loadImage(ContentResolver contentResolver, Uri uri, int maxHeight, int maxWidth) throws FileNotFoundException {
32 | BitmapFactory.Options options = null;
33 | Bitmap bitmap = null;
34 | InputStream inputStream;
35 | try {
36 | options = calculateInSampleSize(contentResolver, uri, maxHeight, maxWidth);
37 | boolean isSuccess = false;
38 | while (!isSuccess) {
39 | try {
40 | inputStream = contentResolver.openInputStream(uri);
41 | bitmap = BitmapFactory.decodeStream(inputStream, null, options);
42 | isSuccess = true;
43 | } catch (OutOfMemoryError error) {
44 | Log.d(TAG, "out of memory");
45 | options.inSampleSize = options.inSampleSize * 2;
46 | isSuccess = false;
47 | }
48 | }
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | return bitmap;
53 |
54 | // TODO: 2017/7/27 除了打开两次输入流还有其他办法嘛
55 | }
56 |
57 | /**
58 | * 检查图片orientation是否有旋转,没有的话返回原图
59 | *
60 | * @param contentResolver 内容提供器
61 | * @param uri 图片的uri
62 | * @param bitmap 原图
63 | * @return 旋转后的图片,如果不需要旋转则返回原图
64 | */
65 | public static Bitmap checkBitmapOrientation(ContentResolver contentResolver, Uri uri, Bitmap bitmap) {
66 | int degree = getBitmapOrientation(contentResolver, uri);
67 | if (degree != 0) {
68 | bitmap = rotateBitmap(bitmap, -degree);
69 | }
70 | return bitmap;
71 | }
72 |
73 | public static int getBitmapOrientation(ContentResolver contentResolver, Uri uri) {
74 | InputStream inputStream;
75 | try {
76 | inputStream = contentResolver.openInputStream(uri);
77 | if (inputStream != null) {
78 | android.support.media.ExifInterface exif = new android.support.media.ExifInterface(inputStream);
79 | int exifOrientation = exif.getAttributeInt(android.support.media.ExifInterface.TAG_DATETIME_ORIGINAL, ExifInterface.ORIENTATION_NORMAL);
80 | return exifToDegrees(exifOrientation);//返回旋转度数
81 | }
82 | } catch (FileNotFoundException e) {
83 | e.printStackTrace();
84 | } catch (IOException e) {
85 | e.printStackTrace();
86 | }
87 | return 0;//
88 | }
89 |
90 |
91 | public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) {
92 | Matrix matrix = new Matrix();
93 | boolean isSuccess = false;
94 | float compressScale = 1;
95 | Bitmap rotatedBitmap;
96 | matrix.setRotate(degrees, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
97 |
98 | while (!isSuccess) {//知道压缩到合适的大小
99 | try {
100 | //如果没有旋转,他是不会创建新图片的
101 | rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
102 | bitmap.recycle();//创建成功,回收先
103 | isSuccess = true;
104 | bitmap = rotatedBitmap;
105 | } catch (OutOfMemoryError error) {
106 | Log.e(TAG, "rotateBitmap out of memory");
107 | error.printStackTrace();
108 | compressScale = compressScale * 0.7f;
109 | matrix.postScale(compressScale, compressScale, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
110 | }
111 | }
112 | return bitmap;
113 | }
114 |
115 |
116 | private static int exifToDegrees(int exifOrientation) {
117 | switch (exifOrientation) {
118 | case ExifInterface.ORIENTATION_ROTATE_90:
119 | return 0;
120 |
121 | case ExifInterface.ORIENTATION_ROTATE_180:
122 | return 180;
123 |
124 | case ExifInterface.ORIENTATION_ROTATE_270:
125 | return 270;
126 | default:
127 | return 0;
128 | }
129 | }
130 |
131 | private static Rect CalculateBitmapSize(ContentResolver contentResolver, Uri uri) throws IOException{
132 | BitmapFactory.Options options = new BitmapFactory.Options();
133 | options.inJustDecodeBounds = true;
134 | InputStream in = contentResolver.openInputStream(uri);
135 | if(in !=null){
136 | BitmapFactory.decodeStream(in,null,options);
137 | }
138 | Rect rect = new Rect();
139 | rect.set(0,0,options.outWidth,options.outHeight);
140 | return rect;
141 | }
142 |
143 | private static BitmapFactory.Options calculateInSampleSize(ContentResolver contentResolver, Uri uri, int maxHeight, int maxWidth) throws IOException {
144 | // TODO: 2017/7/28 应该怎么对参数进行限制?,所有参数都得判断 ?
145 | BitmapFactory.Options options = new BitmapFactory.Options();
146 | options.inJustDecodeBounds = true;
147 | InputStream inputStream = contentResolver.openInputStream(uri);
148 | if (inputStream != null) {
149 | BitmapFactory.decodeStream(inputStream, null, options);
150 | int width = options.outWidth;
151 | int height = options.outHeight;
152 | int scale = 1;
153 | while (height > maxHeight && width > maxWidth) {
154 | height /= 2;
155 | width /= 2;
156 | scale = scale * 2;
157 | }
158 | options.inSampleSize = scale;//缩小倍数
159 | options.inJustDecodeBounds = false;
160 | inputStream.close();
161 | }
162 |
163 | return options;
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/util/RectUtils.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.util;
2 |
3 | import android.graphics.RectF;
4 |
5 | public class RectUtils {
6 |
7 | public static float[] getCornersFromRect(RectF r) {
8 | return new float[]{
9 | r.left, r.top,
10 | r.right, r.top,
11 | r.right, r.bottom,
12 | r.left, r.bottom
13 | };
14 | }
15 |
16 |
17 | public static float[] getRectSidesFromCorners(float[] corners) {
18 | return new float[]{(float) Math.sqrt(Math.pow(corners[0] - corners[2], 2) + Math.pow(corners[1] - corners[3], 2)),
19 | (float) Math.sqrt(Math.pow(corners[2] - corners[4], 2) + Math.pow(corners[3] - corners[5], 2))};
20 | }
21 |
22 | public static float[] getCenterFromRect(RectF r) {
23 | return new float[]{r.centerX(), r.centerY()};
24 | }
25 |
26 |
27 | public static RectF trapToRect(float[] array) {
28 | RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
29 | Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
30 | for (int i = 1; i < array.length; i += 2) {
31 | float x = Math.round(array[i - 1] * 10) / 10.f;
32 | float y = Math.round(array[i] * 10) / 10.f;
33 | r.left = (x < r.left) ? x : r.left;
34 | r.top = (y < r.top) ? y : r.top;
35 | r.right = (x > r.right) ? x : r.right;
36 | r.bottom = (y > r.bottom) ? y : r.bottom;
37 | }
38 | r.sort();
39 | return r;
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/util/RotationGestureDetector.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.util;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.view.MotionEvent;
5 |
6 | public class RotationGestureDetector {
7 |
8 | private static final int INVALID_POINTER_INDEX = -1;
9 |
10 | private float fX, fY, sX, sY;
11 |
12 | private int mPointerIndex1, mPointerIndex2;
13 | private float mAngle;
14 | private boolean mIsFirstTouch;
15 |
16 | private OnRotationGestureListener mListener;
17 |
18 | public RotationGestureDetector(OnRotationGestureListener listener) {
19 | mListener = listener;
20 | mPointerIndex1 = INVALID_POINTER_INDEX;
21 | mPointerIndex2 = INVALID_POINTER_INDEX;
22 | }
23 |
24 | public float getAngle() {
25 | return mAngle;
26 | }
27 |
28 | public boolean onTouchEvent(@NonNull MotionEvent event) {
29 | switch (event.getActionMasked()) {
30 | case MotionEvent.ACTION_DOWN:
31 | sX = event.getX();
32 | sY = event.getY();
33 | mPointerIndex1 = event.findPointerIndex(event.getPointerId(0));
34 | mAngle = 0;
35 | mIsFirstTouch = true;
36 | break;
37 | case MotionEvent.ACTION_POINTER_DOWN:
38 | fX = event.getX();
39 | fY = event.getY();
40 | mPointerIndex2 = event.findPointerIndex(event.getPointerId(event.getActionIndex()));
41 | mAngle = 0;
42 | mIsFirstTouch = true;
43 | break;
44 | case MotionEvent.ACTION_MOVE:
45 | if (mPointerIndex1 != INVALID_POINTER_INDEX && mPointerIndex2 != INVALID_POINTER_INDEX && event.getPointerCount() > mPointerIndex2) {
46 | float nfX, nfY, nsX, nsY;
47 |
48 | nsX = event.getX(mPointerIndex1);
49 | nsY = event.getY(mPointerIndex1);
50 | nfX = event.getX(mPointerIndex2);
51 | nfY = event.getY(mPointerIndex2);
52 |
53 | if (mIsFirstTouch) {
54 | mAngle = 0;
55 | mIsFirstTouch = false;
56 | } else {
57 | calculateAngleBetweenLines(fX, fY, sX, sY, nfX, nfY, nsX, nsY);
58 | }
59 |
60 | if (mListener != null) {
61 | mListener.onRotation(this);
62 | }
63 | fX = nfX;
64 | fY = nfY;
65 | sX = nsX;
66 | sY = nsY;
67 | }
68 | break;
69 | case MotionEvent.ACTION_UP:
70 | mPointerIndex1 = INVALID_POINTER_INDEX;
71 | break;
72 | case MotionEvent.ACTION_POINTER_UP:
73 | mPointerIndex2 = INVALID_POINTER_INDEX;
74 | break;
75 | default:
76 | break;
77 | }
78 | return true;
79 | }
80 |
81 | private float calculateAngleBetweenLines(float fx1, float fy1, float fx2, float fy2,
82 | float sx1, float sy1, float sx2, float sy2) {
83 | return calculateAngleDelta(
84 | (float) Math.toDegrees((float) Math.atan2((fy1 - fy2), (fx1 - fx2))),
85 | (float) Math.toDegrees((float) Math.atan2((sy1 - sy2), (sx1 - sx2))));
86 | }
87 |
88 | private float calculateAngleDelta(float angleFrom, float angleTo) {
89 | mAngle = angleTo % 360.0f - angleFrom % 360.0f;
90 |
91 | if (mAngle < -180.0f) {
92 | mAngle += 360.0f;
93 | } else if (mAngle > 180.0f) {
94 | mAngle -= 360.0f;
95 | }
96 |
97 | return mAngle;
98 | }
99 |
100 | public static class SimpleOnRotationGestureListener implements OnRotationGestureListener {
101 |
102 | @Override
103 | public boolean onRotation(RotationGestureDetector rotationDetector) {
104 | return false;
105 | }
106 | }
107 |
108 | public interface OnRotationGestureListener {
109 |
110 | boolean onRotation(RotationGestureDetector rotationDetector);
111 | }
112 |
113 | }
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/util/SaveBitmapCallback.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.util;
2 |
3 | /**
4 | * Created by zmc on 2017/7/27.
5 | */
6 |
7 | public interface SaveBitmapCallback {
8 |
9 | void onFailed();
10 | }
11 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/java/com/meitu/cropimagelibrary/view/CropImageView.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary.view;
2 |
3 | import android.animation.Animator;
4 | import android.animation.PropertyValuesHolder;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.Rect;
13 | import android.graphics.RectF;
14 | import android.graphics.drawable.BitmapDrawable;
15 | import android.graphics.drawable.Drawable;
16 | import android.net.Uri;
17 | import android.support.annotation.NonNull;
18 | import android.support.annotation.Nullable;
19 | import android.util.AttributeSet;
20 | import android.util.Log;
21 | import android.view.GestureDetector;
22 | import android.view.MotionEvent;
23 | import android.view.ScaleGestureDetector;
24 |
25 | import com.meitu.cropimagelibrary.info.ImageInfo;
26 | import com.meitu.cropimagelibrary.util.ImageLoadUtil;
27 | import com.meitu.cropimagelibrary.util.RectUtils;
28 | import com.meitu.cropimagelibrary.util.RotationGestureDetector;
29 |
30 | import java.io.FileNotFoundException;
31 | import java.util.Arrays;
32 |
33 | /**
34 | * Created by zmc on 2017/7/18.
35 | */
36 |
37 | public class CropImageView extends android.support.v7.widget.AppCompatImageView {
38 |
39 |
40 | private static final String DEFAULT_BACKGROUND_COLOR_ID = "#99000000";//超过裁剪部分的矩形框
41 | private static final String TAG = "CropImageView";
42 | private static final long DEFAULT_ANIMATION_TIME = 500;
43 | private boolean isHorizontalEnable = false;
44 | private boolean isVerticalEnable = false;
45 | private float mMaxScale = 3f;
46 |
47 |
48 | private float mMinScale = 0.8f;
49 | private boolean mScaleEnable = true;
50 | private boolean mRotateEnable = true;
51 |
52 |
53 | private final Matrix mBaseMatrix = new Matrix();
54 | private final Matrix mDisplayMatrix = new Matrix();
55 | private final Matrix mTempMatrix = new Matrix();
56 | private final Matrix mMirrorMatrix = new Matrix();
57 | private final Matrix mConcatMatrix = new Matrix();
58 |
59 | private final RectF mCropRectF = new RectF();//裁剪框矩形区域
60 | private final RectF mBitmapRectF = new RectF();//当前的矩形区域
61 |
62 | private Paint mTransParentLayerPaint;//暗色区域背景
63 | private Paint mWhiteCropPaint;
64 |
65 |
66 | private ScaleGestureDetector mScaleGestureDetector;
67 | private GestureDetector mGestureDetector;
68 | private RotationGestureDetector mRotationGestureDetector;
69 |
70 | private float mMidPntX, mMidPntY;//手指中心点
71 |
72 |
73 | private final float[] mMatrixValue = new float[9];
74 |
75 | private ImageInfo mImageInfo;//最开始图片信息,好像可以删掉
76 |
77 |
78 | private final float[] mCurrentImageCorners = new float[8];//用来存放当前顶点坐标啊
79 | private float[] mInitImageCorners;
80 | private Uri mUri;//图片的uri
81 |
82 | private TransformAnimator mRotateAnimator;
83 | private TransformAnimator mTranslateScaleAnimator;
84 | private Animator mCurrentActiveAnimator;
85 |
86 |
87 | public CropImageView(Context context) {
88 | this(context, null, 0);
89 | }
90 |
91 | public CropImageView(Context context, @Nullable AttributeSet attrs) {
92 | this(context, attrs, 0);
93 | }
94 |
95 | public CropImageView(Context context, AttributeSet attrs, int defStyleAttr) {
96 | super(context, attrs, defStyleAttr);
97 | init();
98 | }
99 |
100 | /**
101 | * 初始化裁剪框和阴影区域的画笔
102 | */
103 | private void initCropMaterials() {
104 |
105 | mTransParentLayerPaint = new Paint();
106 | mTransParentLayerPaint.setColor(Color.parseColor(DEFAULT_BACKGROUND_COLOR_ID));//设置颜色
107 |
108 | mWhiteCropPaint = new Paint();
109 | mWhiteCropPaint.setColor(Color.WHITE);//设置颜色
110 | mWhiteCropPaint.setStrokeWidth(1);//设置填充宽度
111 | mWhiteCropPaint.setStyle(Paint.Style.STROKE);//what??
112 | }
113 |
114 |
115 | private void init() {
116 | initCropMaterials();
117 |
118 | mInitImageCorners = new float[8];
119 |
120 | mScaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
121 | mGestureDetector = new GestureDetector(getContext(), new GestureListener());
122 | mRotationGestureDetector = new RotationGestureDetector(new RotationListener());
123 |
124 | initAnimator();
125 |
126 | }
127 |
128 | /**
129 | * 初始化移动和放大得用的ValueAnimator
130 | */
131 | private void initAnimator() {
132 | mRotateAnimator = new TransformAnimator();
133 | mRotateAnimator.setDuration(DEFAULT_ANIMATION_TIME);
134 | mRotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
135 |
136 | @Override
137 | public void onAnimationUpdate(ValueAnimator animation) {
138 | float goalRotate = (float) animation.getAnimatedValue();
139 | float postRotate = goalRotate - mRotateAnimator.getLastRote();
140 | mRotateAnimator.setLastRote(goalRotate);
141 | postRotate(postRotate, mCropRectF.centerX(), mCropRectF.centerY());
142 | }
143 | });
144 | mRotateAnimator.addListener(new Animator.AnimatorListener() {
145 | @Override
146 | public void onAnimationStart(Animator animation) {
147 | mRotateAnimator.setLastRote(0);
148 | }
149 |
150 | @Override
151 | public void onAnimationEnd(Animator animation) {
152 | checkImagePosition();
153 | mRotateAnimator.setLastRote(0);
154 | }
155 |
156 | @Override
157 | public void onAnimationCancel(Animator animation) {
158 |
159 | }
160 |
161 | @Override
162 | public void onAnimationRepeat(Animator animation) {
163 |
164 | }
165 | });
166 |
167 | mTranslateScaleAnimator = new TransformAnimator();
168 | mTranslateScaleAnimator.setDuration(DEFAULT_ANIMATION_TIME);
169 | mTranslateScaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
170 | @Override
171 | public void onAnimationUpdate(ValueAnimator animation) {
172 | float goalTranslateX = (float) animation.getAnimatedValue(TransformAnimator.PROPERTY_NAME_TRANSLATE_X);
173 | float goalTranslateY = (float) animation.getAnimatedValue(TransformAnimator.PROPERTY_NAME_TRANSLATE_Y);
174 | float goalScale_XAndY = (float) animation.getAnimatedValue(TransformAnimator.PROPERTY_NAME_SCALE_XANDY);
175 | if (Float.isNaN(goalTranslateX) || Float.isNaN(goalTranslateY) || Float.isNaN(goalScale_XAndY)) {
176 | return;
177 | }
178 | Log.d(TAG, "goalTranslateX:" + goalTranslateX + "goalTranslateY:" + goalTranslateY + "goalScale_XAndY:" + goalScale_XAndY);
179 | float postTranslateX = goalTranslateX - mTranslateScaleAnimator.getLastTraslateX();
180 | float postTranslateY = goalTranslateY - mTranslateScaleAnimator.getLastTraslateY();
181 | float postScaleXAndY = goalScale_XAndY / mTranslateScaleAnimator.getLastScale();
182 |
183 | mTranslateScaleAnimator.setLastTraslateX(goalTranslateX);
184 | mTranslateScaleAnimator.setLastTraslateY(goalTranslateY);
185 | mTranslateScaleAnimator.setLastScale(goalScale_XAndY);
186 | Log.d(TAG, "postTranslateX:" + postTranslateX + "postTranslateY:" + postTranslateY + "postScaleXAndY:" + postScaleXAndY);
187 | postTranslateAndScale(postTranslateX, postTranslateY, postScaleXAndY);
188 | }
189 | });
190 | mTranslateScaleAnimator.addListener(new Animator.AnimatorListener() {
191 | @Override
192 | public void onAnimationStart(Animator animation) {
193 | mTranslateScaleAnimator.setLastScale(1);
194 | mTranslateScaleAnimator.setLastTraslateX(0);
195 | mTranslateScaleAnimator.setLastTraslateY(0);
196 | }
197 |
198 | @Override
199 | public void onAnimationEnd(Animator animation) {
200 | mTranslateScaleAnimator.setLastScale(1);
201 | mTranslateScaleAnimator.setLastTraslateX(0);
202 | mTranslateScaleAnimator.setLastTraslateY(0);
203 | // checkImagePosition();
204 |
205 | }
206 |
207 | @Override
208 | public void onAnimationCancel(Animator animation) {
209 | }
210 |
211 | @Override
212 | public void onAnimationRepeat(Animator animation) {
213 |
214 | }
215 | });
216 | }
217 |
218 | /**
219 | * 同时位移和放大
220 | *
221 | * @param translateX 位移x量
222 | * @param translateY 位移y量
223 | * @param scale_xAndY 放大x和y的放大倍数
224 | */
225 | private void postTranslateAndScale(float translateX, float translateY, float scale_xAndY) {
226 | mDisplayMatrix.postTranslate(translateX, translateY);
227 | updateBitmapRectf(mDisplayMatrix);
228 | mDisplayMatrix.postScale(scale_xAndY, scale_xAndY, mBitmapRectF.centerX(), mBitmapRectF.centerY());
229 | setImageMatrix(getConcatMatrix());
230 | }
231 |
232 | /**
233 | * 设置最小放大倍数
234 | *
235 | * @param MIN_SCALE 最小放大倍数
236 | */
237 | public void setMinScale(float MIN_SCALE) {
238 | this.mMinScale = MIN_SCALE;
239 | }
240 |
241 | /**
242 | * 设置最小放大倍数
243 | *
244 | * @param MAX_SCALE 最大放大倍数
245 | */
246 | public void setMaxScale(float MAX_SCALE) {
247 | this.mMaxScale = MAX_SCALE;
248 | }
249 |
250 |
251 | @Override
252 | public boolean onTouchEvent(MotionEvent event) {
253 |
254 | if (getImageBitmap() != null) {
255 | if (mCurrentActiveAnimator != null) {
256 | mCurrentActiveAnimator.cancel();
257 | }
258 |
259 | if (event.getPointerCount() > 1) {
260 | mMidPntX = (event.getX(0) + event.getX(1)) / 2;//算出中心点
261 | mMidPntY = (event.getY(0) + event.getY(1)) / 2;
262 | }
263 |
264 |
265 | if (mScaleEnable) {
266 | mScaleGestureDetector.onTouchEvent(event);
267 | }
268 | if (mRotateEnable) {
269 | mRotationGestureDetector.onTouchEvent(event);
270 | }
271 |
272 | if (!mScaleGestureDetector.isInProgress()) {
273 | //检测拖动
274 | mGestureDetector.onTouchEvent(event);
275 | }
276 |
277 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {//松手动手
278 | checkImagePosition();
279 | }
280 | return true;
281 | } else {
282 | return false;
283 | }
284 | }
285 |
286 |
287 | /**
288 | * 放大设置开关
289 | *
290 | * @param mScaleEnable 是否开启
291 | */
292 | public void setScaleEnable(boolean mScaleEnable) {
293 | this.mScaleEnable = mScaleEnable;
294 | }
295 |
296 | /**
297 | * 旋转开关
298 | *
299 | * @param mRotateEnable 是否开启
300 | */
301 | public void setRotateEnable(boolean mRotateEnable) {
302 | this.mRotateEnable = mRotateEnable;
303 | }
304 |
305 |
306 | @Override
307 | public void setScaleType(ScaleType scaleType) {
308 | if (scaleType != ScaleType.MATRIX) {
309 | throw new IllegalArgumentException("scaleType must be matrix");
310 | } else {
311 | super.setScaleType(scaleType);
312 | }
313 | }
314 |
315 | /**
316 | * 检车是否越界
317 | */
318 | private void checkImagePosition() {
319 | Log.d(TAG, "现在放大倍数为:" + getCurrentScale() + "初始的放大倍数为:" + mImageInfo.getInitScale());
320 | if (getCurrentScale() > mMaxScale) {
321 | backToMaxScale();
322 | }
323 | mDisplayMatrix.mapPoints(mCurrentImageCorners, mInitImageCorners);//求出当前的坐标
324 | float dx, dy;//中心便宜距离
325 | float deltaScale = 1;
326 | updateBitmapRectf(mDisplayMatrix);
327 | dx = mCropRectF.centerX() - mBitmapRectF.centerX();//拿到需要移动距离
328 | dy = mCropRectF.centerY() - mBitmapRectF.centerY();
329 | //判断回到中心后能不能回到覆盖
330 | mTempMatrix.reset();
331 | mTempMatrix.set(mDisplayMatrix);//设置当前的位置
332 | mTempMatrix.postTranslate(dx, dy);//回到中心点
333 | float[] tempImageCorners = Arrays.copyOf(mInitImageCorners, mInitImageCorners.length);//拷贝一份初始点
334 | mTempMatrix.mapPoints(tempImageCorners);//获取移动到中心点的各个坐标
335 |
336 | boolean isWillImageWrapCropBounds = isImageWrapCropBounds(tempImageCorners);
337 | Log.d(TAG, "checkImagePosition" + "假如图片移到中心,是否覆盖裁剪框" + isWillImageWrapCropBounds);
338 | //可以话只求出移动的距离,否则求出放大倍数
339 | if (isWillImageWrapCropBounds) {
340 | final float[] imageIndents = calculateImageIndents();
341 | dx = -(imageIndents[0] + imageIndents[2]);//估计现在和那个之前的距离
342 | dy = -(imageIndents[1] + imageIndents[3]);
343 | } else {//表示没有包裹
344 | RectF tempCropRect = new RectF(mCropRectF);
345 | mTempMatrix.reset();
346 | mTempMatrix.setRotate(getCurrentAngle());//摸你旋转角度
347 | mTempMatrix.mapRect(tempCropRect);//吧矩形框转到和图像一样的角度
348 |
349 | final float[] currentImageSides = RectUtils.getRectSidesFromCorners(mCurrentImageCorners);//得到分别是宽和高
350 |
351 | deltaScale = Math.max(tempCropRect.width() / currentImageSides[0],
352 | tempCropRect.height() / currentImageSides[1]);
353 | Log.d(TAG, "checkImagePosition" + "不可以覆盖裁剪框,需要放大倍数为" + "dx" + deltaScale);
354 | }
355 |
356 | //再放大
357 | if (isWillImageWrapCropBounds) {//只移动就可以
358 | mTranslateScaleAnimator.setValues(PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_TRANSLATE_X, 0, dx),
359 | PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_TRANSLATE_Y, 0, dy),
360 | PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_SCALE_XANDY, 1f, 1f));//相当于不放大
361 | Log.d(TAG, "可以覆盖裁剪框,需要移动距离为" + "dx" + dx + " dy " + dy);
362 | } else {
363 | mTranslateScaleAnimator.setValues(PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_TRANSLATE_X, 0, dx),
364 | PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_TRANSLATE_Y, 0, dy),
365 | PropertyValuesHolder.ofFloat(TransformAnimator.PROPERTY_NAME_SCALE_XANDY, 1f, deltaScale));//相当于不放大
366 | Log.d(TAG, "可以覆盖裁剪框,需要移动距离为" + "dx" + dx + " dy " + dy);
367 | }
368 | //设置矩阵并重绘
369 | mCurrentActiveAnimator = mTranslateScaleAnimator;
370 | mTranslateScaleAnimator.start();
371 |
372 | }
373 |
374 |
375 | private void backToMaxScale() {
376 | float scale = mMaxScale / getCurrentScale();
377 | Log.d(TAG, "要回弹的倍数" + scale + "到最大倍数" + mMaxScale);
378 | mDisplayMatrix.postScale(scale, scale, mCropRectF.centerX(), mCropRectF.centerY());
379 | setImageMatrix(getConcatMatrix());
380 | }
381 |
382 |
383 | /**
384 | * 计算出当图片小于裁剪框时候的间距,即离那个角的平行距离
385 | *
386 | * @return 4个角垂直距离
387 | */
388 | private float[] calculateImageIndents() {
389 | mTempMatrix.reset();
390 | mTempMatrix.setRotate(-getCurrentAngle());
391 |
392 | float[] unrotatedImageCorners = Arrays.copyOf(mCurrentImageCorners, mCurrentImageCorners.length);
393 | float[] unrotatedCropBoundsCorners = RectUtils.getCornersFromRect(mCropRectF);
394 |
395 | mTempMatrix.mapPoints(unrotatedImageCorners);
396 | mTempMatrix.mapPoints(unrotatedCropBoundsCorners);
397 |
398 | RectF unrotatedImageRect = RectUtils.trapToRect(unrotatedImageCorners);
399 | RectF unrotatedCropRect = RectUtils.trapToRect(unrotatedCropBoundsCorners);
400 |
401 | float deltaLeft = unrotatedImageRect.left - unrotatedCropRect.left;
402 | float deltaTop = unrotatedImageRect.top - unrotatedCropRect.top;
403 | float deltaRight = unrotatedImageRect.right - unrotatedCropRect.right;
404 | float deltaBottom = unrotatedImageRect.bottom - unrotatedCropRect.bottom;
405 |
406 | float indents[] = new float[4];
407 | indents[0] = (deltaLeft > 0) ? deltaLeft : 0;
408 | indents[1] = (deltaTop > 0) ? deltaTop : 0;
409 | indents[2] = (deltaRight < 0) ? deltaRight : 0;
410 | indents[3] = (deltaBottom < 0) ? deltaBottom : 0;
411 |
412 | mTempMatrix.reset();
413 | mTempMatrix.setRotate(getCurrentAngle());
414 | mTempMatrix.mapPoints(indents);
415 |
416 | return indents;
417 | }
418 |
419 | /**
420 | * 计算是图片是否包裹了裁剪框
421 | *
422 | * @param imageCorners 图片各个角的坐标
423 | * @return true表示图片够大如果移动到中心已经包裹裁剪框
424 | */
425 | protected boolean isImageWrapCropBounds(float[] imageCorners) {
426 | mTempMatrix.reset();
427 | mTempMatrix.setRotate(-getCurrentAngle());
428 |
429 | float[] unrotatedImageCorners = Arrays.copyOf(imageCorners, imageCorners.length);
430 | mTempMatrix.mapPoints(unrotatedImageCorners);//把矩阵摆正嘛?
431 |
432 | float[] unrotatedCropBoundsCorners = RectUtils.getCornersFromRect(mCropRectF);
433 | mTempMatrix.mapPoints(unrotatedCropBoundsCorners);
434 | //脑残吧?把图片旋转却旋转框框,
435 | return RectUtils.trapToRect(unrotatedImageCorners).contains(RectUtils.trapToRect(unrotatedCropBoundsCorners));
436 |
437 | }
438 |
439 |
440 | /**
441 | * 获得当前的旋转角度
442 | */
443 | public float getCurrentAngle() {
444 | return getMatrixAngle(mDisplayMatrix);
445 | }
446 |
447 | /**
448 | * 获得当前的放大倍数
449 | */
450 | public float getCurrentScale() {
451 |
452 | float displayScale = getMatrixScale(mDisplayMatrix);
453 | return displayScale / mImageInfo.getInitScale();
454 | }
455 |
456 |
457 | /**
458 | * @param matrix 应为这个库xy放大倍数相同,所以只去一个方向放大倍数代表现在放大倍数
459 | * @return 放大倍数
460 | */
461 | public float getMatrixScale(@NonNull Matrix matrix) {
462 | return (float) Math.sqrt(Math.pow(getMatrixValue(matrix, Matrix.MSCALE_X), 2) + Math.pow(getMatrixValue(matrix, Matrix.MSKEW_Y), 2));
463 | }
464 |
465 | /**
466 | * 获得对应矩阵的旋转角度
467 | */
468 | public float getMatrixAngle(@NonNull Matrix matrix) {
469 | return (float) -(Math.atan2(getMatrixValue(matrix, Matrix.MSKEW_X),
470 | getMatrixValue(matrix, Matrix.MSCALE_X)) * (180 / Math.PI));
471 | }
472 |
473 | protected float getMatrixValue(@NonNull Matrix matrix, int valueIndex) {
474 | matrix.getValues(mMatrixValue);
475 | return mMatrixValue[valueIndex];
476 | }
477 |
478 | /**
479 | * 设置成水平镜像
480 | */
481 | public void setHorizontalMirror() {
482 |
483 |
484 | mMirrorMatrix.postScale(-1f, 1f, mCropRectF.centerX(), mCropRectF.centerY());
485 | setImageMatrix(getConcatMatrix());
486 | isHorizontalEnable = !isHorizontalEnable;
487 | invalidate();
488 |
489 | }
490 |
491 | /**
492 | * 连接矩阵,主要将display矩阵和镜像矩阵进行连接
493 | *
494 | * @return 返回合成后的矩阵
495 | */
496 | public Matrix getConcatMatrix() {
497 | mConcatMatrix.reset();
498 | mConcatMatrix.set(mDisplayMatrix);
499 | mConcatMatrix.postConcat(mMirrorMatrix);
500 | return mConcatMatrix;
501 | }
502 |
503 |
504 | /**
505 | * 设置成水平镜像
506 | */
507 | public void setVerticalMirror() {
508 | mMirrorMatrix.postScale(1f, -1f, mCropRectF.centerX(), mCropRectF.centerY());
509 | setImageMatrix(getConcatMatrix());
510 | isVerticalEnable = true;
511 | invalidate();
512 | }
513 |
514 | public void rightRotate90() {
515 | postAnyRotate(90f);
516 | }
517 |
518 | private void postRotate(float angel, float centerX, float centerY) {
519 | mDisplayMatrix.postRotate(angel, centerX, centerY);
520 | setImageMatrix(getConcatMatrix());
521 | }
522 |
523 | public void leftRotate90() {
524 | postAnyRotate(-90f);
525 | }
526 |
527 | public void postAnyRotate(float anyAngel) {
528 | if (getImageBitmap() != null) {
529 | mRotateAnimator.cancel();
530 | mRotateAnimator.setFloatValues(0, anyAngel);
531 | mRotateAnimator.setDuration(DEFAULT_ANIMATION_TIME);
532 | mCurrentActiveAnimator = mRotateAnimator;
533 | mRotateAnimator.start();
534 | }
535 | }
536 |
537 |
538 | /**
539 | * 移动Bitmap的位置
540 | *
541 | * @param dx x轴移动的距离
542 | * @param dy y轴移动的距离
543 | */
544 | private void moveImage(float dx, float dy) {
545 | mDisplayMatrix.postTranslate(dx, dy);
546 | setImageMatrix(getConcatMatrix());
547 | invalidate();
548 | }
549 |
550 | @Override
551 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
552 | super.onLayout(changed, left, top, right, bottom);
553 | float mThisWidth = getMeasuredWidth();
554 | float mThisHeight = getMeasuredHeight();
555 |
556 | mCropRectF.set(0, (mThisHeight - mThisWidth) / 2, mThisWidth, (mThisHeight + mThisWidth) / 2);//这里初始化好矩形框框的范围
557 |
558 | if (getDrawable() != null) {
559 | getProperMatrix(mBaseMatrix);//获取矩阵,用来设置矩阵
560 | //拷贝矩阵
561 | mDisplayMatrix.set(mBaseMatrix);
562 | setImageMatrix(getConcatMatrix());
563 |
564 | //设置化映射矩阵
565 | mBitmapRectF.set(0, 0, getDrawable().getIntrinsicWidth(), getDrawable().getIntrinsicHeight());
566 |
567 | mInitImageCorners = RectUtils.getCornersFromRect(mBitmapRectF);//获取初始化的点
568 | }
569 | }
570 |
571 | private void updateBitmapRectf(Matrix displayMatrix) {
572 | if (getDrawable() != null) {
573 | mBitmapRectF.set(0, 0, getDrawable().getIntrinsicWidth(), getDrawable().getIntrinsicHeight());
574 | displayMatrix.mapRect(mBitmapRectF);
575 | }
576 | }
577 |
578 | /**
579 | * 获取让图片移动并居中到裁剪框的举证
580 | *
581 | * @param baseMatrix 展示用的矩阵
582 | */
583 | private void getProperMatrix(Matrix baseMatrix) {
584 | baseMatrix.reset();
585 | Drawable drawable = getDrawable();
586 | float intrinsicWidth = drawable.getIntrinsicWidth();
587 | float intrinsicHeight = drawable.getIntrinsicHeight();
588 | float drawableRatio = intrinsicHeight / intrinsicWidth;//图片的高/宽 比例
589 |
590 | float cropRectWidth = mCropRectF.width();
591 | float cropRectHeight = mCropRectF.height();
592 | float cropRectRatio = cropRectHeight / cropRectWidth;
593 |
594 | //
595 | float scale;
596 | float moveX = 0, moveY;
597 | if (drawableRatio > cropRectRatio) {//表示是长图,就是高大于宽
598 | //按照宽的比例来扩大
599 | scale = cropRectWidth / intrinsicWidth;
600 | moveY = (getMeasuredHeight() - intrinsicHeight * scale) / 2;//视图的高度减去图片的扩大后的高度/2
601 | } else {
602 | //按照高的比例来扩大
603 | scale = cropRectHeight / intrinsicHeight;
604 | moveX = (cropRectWidth - scale * intrinsicWidth) / 2;
605 | moveY = mCropRectF.top;
606 | }
607 | baseMatrix.postScale(scale, scale);//设置恰当的放大倍数
608 | baseMatrix.postTranslate(moveX, moveY);
609 | }
610 |
611 | @Override
612 | protected void onDraw(Canvas canvas) {
613 | long start = System.currentTimeMillis();
614 | Log.d(TAG, mDisplayMatrix.toString());
615 | super.onDraw(canvas);
616 | drawTransParentLayer(canvas);
617 | drawCropRect(canvas);
618 |
619 | if (getDrawable() != null) {
620 | logMatrixInfo(getImageMatrix());
621 | if (mImageInfo == null) {//第一次才需要记录,最开始高宽和长度,和放大倍数
622 | setImageInfo();
623 | }
624 | }
625 | Log.d("onDrawTime",""+(System.currentTimeMillis() - start));
626 | }
627 |
628 | private void setImageInfo() {
629 |
630 | mImageInfo = new ImageInfo(getDrawable().getIntrinsicWidth(), getDrawable().getIntrinsicHeight(), getMatrixScale(mDisplayMatrix));
631 | }
632 |
633 | /**
634 | * 绘画阴影区域
635 | *
636 | * @param canvas 画布
637 | */
638 | private void drawTransParentLayer(Canvas canvas) {
639 | Rect r = new Rect();
640 | getLocalVisibleRect(r);
641 | canvas.drawRect(r.left, r.top, r.right, mCropRectF.top, mTransParentLayerPaint);
642 | canvas.drawRect(r.left, mCropRectF.bottom, r.right, r.bottom, mTransParentLayerPaint);
643 | }
644 |
645 | private void drawCropRect(Canvas canvas) {
646 | float halfLineWidth = mWhiteCropPaint.getStrokeWidth() * 0.5f;
647 | canvas.drawRect(mCropRectF.left + halfLineWidth, mCropRectF.top - halfLineWidth, mCropRectF.right - halfLineWidth, mCropRectF.bottom + halfLineWidth, mWhiteCropPaint);
648 | }
649 |
650 |
651 | @Override
652 | public void setImageURI(@Nullable Uri uri) {
653 | if (uri != null) {
654 | mUri = uri;
655 | //super.setImageURI(uri);
656 | try {
657 | Bitmap bmp = ImageLoadUtil.loadImage(getContext().getContentResolver(), uri, 1500, 1500);
658 | Bitmap rotatedBitmap = ImageLoadUtil.checkBitmapOrientation(getContext().getContentResolver(), uri, bmp);//检查图片方向
659 | setImageBitmap(rotatedBitmap);
660 | } catch (FileNotFoundException e) {
661 | e.printStackTrace();
662 | }
663 | }
664 | }
665 |
666 | public void setDrawable(Drawable drawable) {
667 | setImageDrawable(drawable);
668 | requestLayout();
669 | invalidate();
670 | }
671 |
672 | /**
673 | * 将图片扩大到指定倍数
674 | *
675 | * @param mScaleFactor 扩大倍数
676 | * @param focusX 放大中心点x坐标
677 | * @param focusY 放大中心点y坐标
678 | */
679 | private void postScale(float mScaleFactor, float focusX, float focusY) {
680 |
681 | mDisplayMatrix.postScale(mScaleFactor, mScaleFactor, focusX, focusY);
682 | setImageMatrix(getConcatMatrix());
683 | }
684 |
685 | /**
686 | * 打印检查log
687 | *
688 | * @param matrix 需要检查的矩阵
689 | */
690 | private void logMatrixInfo(Matrix matrix) {
691 | matrix.getValues(mMatrixValue);
692 | Log.d(TAG, "SCALEX:" + mMatrixValue[Matrix.MSCALE_X] + "ScaleY: " + mMatrixValue[Matrix.MSCALE_Y] + "transX "
693 | + mMatrixValue[Matrix.MTRANS_X] + " transY " + mMatrixValue[Matrix.MTRANS_Y]);
694 | Log.d(TAG, "Drawable width " + getDrawable().getIntrinsicWidth() + "Drawable height" + getDrawable().getIntrinsicHeight());
695 | Log.d(TAG, "BitmapRect " + mBitmapRectF.width() + " Bitmap left " + mBitmapRectF.left);
696 |
697 | RectF r = new RectF(0, 0, 100, 100);
698 | Matrix m = new Matrix();
699 | m.setRotate(100);
700 | m.mapRect(r);
701 |
702 | Log.d(TAG, "rotateRectWidth" + r.width());
703 | }
704 |
705 | /**
706 | * @return 返回当前的Bitmap对象
707 | */
708 | public Bitmap getImageBitmap() {
709 | BitmapDrawable bitmapDrawable = (BitmapDrawable) getDrawable();
710 | if (bitmapDrawable != null) {
711 | return bitmapDrawable.getBitmap();
712 | } else {
713 | return null;
714 | }
715 |
716 | }
717 |
718 |
719 | /**
720 | * 裁剪并保存图片
721 | *
722 | * @return 返回需要保存图片的BItmap对象
723 | */
724 | public Bitmap cropAndSaveImage() {
725 | Bitmap bitmap = getImageBitmap();
726 | Bitmap originBitmapFromUri = null;
727 | if (bitmap != null) {
728 | //当前的大图
729 | try {
730 | originBitmapFromUri = ImageLoadUtil.loadImage(getContext().getContentResolver(), mUri, Integer.MAX_VALUE, Integer.MAX_VALUE);//可能oom
731 | } catch (FileNotFoundException e) {
732 | e.printStackTrace();
733 | }
734 | }
735 |
736 | //此时已经拿到最初的放大倍数
737 | //求出裁剪框和大图的相对位置dx,dy;
738 | if (bitmap != null && originBitmapFromUri != null) {
739 | Matrix matrix = new Matrix();
740 | float scale = 1;
741 | Bitmap scaledBitmap, resultBitmap = null;
742 | boolean isSuccess = false, needScale = false;
743 | Bitmap currentRotatedBitmap = getCurrentRotatedOriginalBitmap(originBitmapFromUri); //,拿到旋转图片
744 | while (!isSuccess) {
745 | try {
746 | if (needScale) {//第一次不需要放大,直接裁剪,
747 | matrix.postScale(scale, scale, currentRotatedBitmap.getWidth() / 2, currentRotatedBitmap.getHeight() / 2);
748 | scaledBitmap = Bitmap.createBitmap(currentRotatedBitmap, 0, 0, currentRotatedBitmap.getWidth(), currentRotatedBitmap.getHeight(), matrix, true);
749 | currentRotatedBitmap.recycle();
750 | resultBitmap = scaledBitmap;
751 | isSuccess = true;
752 | }
753 | return getCropBitmapInOriginalBitmap(currentRotatedBitmap);//拿到裁剪框位置的图片,
754 |
755 | } catch (OutOfMemoryError e) {
756 | scale = scale * 0.7f;
757 | needScale = true;
758 | }
759 | }
760 | return resultBitmap;
761 | } else {
762 | return null;
763 | }
764 | }
765 |
766 |
767 | /**
768 | * 拿到裁剪框所在原图的位置
769 | *
770 | * @param currentRotatedBitmap 旋转后的原图
771 | * @return 裁剪框所在位置的图片
772 | * @throws OutOfMemoryError 内存溢出
773 | */
774 | public Bitmap getCropBitmapInOriginalBitmap(Bitmap currentRotatedBitmap) throws OutOfMemoryError {
775 |
776 |
777 | float scale_x = mBitmapRectF.width() / currentRotatedBitmap.getWidth();
778 | float scale_y = mBitmapRectF.height() / currentRotatedBitmap.getHeight();
779 | float initScale = Math.min(scale_x, scale_y);//这个裁剪框和要裁剪的原图的长宽比
780 | //算出裁剪框所在原图的位置,还有裁剪框映射到原图的长和宽
781 | int dx = (int) ((mCropRectF.left - mBitmapRectF.left) / initScale);
782 | int dy = (int) ((mCropRectF.top - mBitmapRectF.top) / initScale);
783 | int width = (int) ((int) mCropRectF.width() / initScale);
784 | int height = (int) ((int) mCropRectF.height() / initScale);
785 | return Bitmap.createBitmap(currentRotatedBitmap, dx, dy, width, height);//这个为输出文件
786 |
787 | }
788 |
789 | /**
790 | * 产生旋转后的源图片
791 | *
792 | * @param originBitmap 原图
793 | * @return 旋转后的图片
794 | * @throws OutOfMemoryError 内存溢出
795 | */
796 | private Bitmap getCurrentRotatedOriginalBitmap(Bitmap originBitmap) {
797 | updateBitmapRectf(mDisplayMatrix);//mBitmapRectf就代表当前矩阵
798 | //获得旋转后的图片
799 | return ImageLoadUtil.rotateBitmap(originBitmap, getCurrentAngle() - ImageLoadUtil.getBitmapOrientation(getContext().getContentResolver(), mUri));
800 | }
801 |
802 | private class GestureListener extends GestureDetector.SimpleOnGestureListener {
803 |
804 | @Override
805 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
806 | if (e1 == null || e2 == null) return false;
807 | if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false;
808 | if (mScaleGestureDetector.isInProgress()) return false;
809 | // TODO: 2017/7/25 如果改成先镜像后移动应该可以解决这个问题
810 | if (isHorizontalEnable) {//设置了水平镜像,往反方向移动,以为镜像是以裁剪框为中心的
811 | distanceX = -distanceX;
812 | }
813 | if (isVerticalEnable) {//设置了水平镜像,往反方向移动,以为镜像是以裁剪框为中心的
814 | distanceY = -distanceY;
815 | }
816 | CropImageView.this.onScroll(distanceX, distanceY);
817 | return true;
818 | }
819 | }
820 |
821 | private void onScroll(float distanceX, float distanceY) {
822 | Log.d(TAG, "onScroll dx " + distanceX + "dy" + distanceY);
823 | moveImage(-distanceX, -distanceY);
824 | }
825 |
826 |
827 | private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
828 |
829 | private float mScaleFactor = 1;
830 | private static final String TAG = "ScaleListener";
831 |
832 |
833 | @Override
834 | public boolean onScale(ScaleGestureDetector detector) {
835 | mScaleFactor = detector.getScaleFactor();
836 |
837 |
838 | // Don't let the object get too small or too large.
839 | mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, mMaxScale));
840 | mScaleFactor = checkScale(mScaleFactor);
841 | Log.d(TAG, "最终手势放大的放大倍数postScale为" + mScaleFactor);
842 | postScale(mScaleFactor, detector.getFocusX(), detector.getFocusY());
843 | Log.d(TAG,"放大focusX"+detector.getFocusX()+"放大focusY"+detector.getFocusY());
844 | mImageInfo.setGestureScale(mImageInfo.getGestureScale() * mScaleFactor);//设置当前放大倍数
845 | return true;
846 | }
847 |
848 | private float checkScale(float scaleFactor) {
849 | float finalScale;
850 | float currentScale = getCurrentScale();
851 | Log.d(TAG, "当前的放大倍数" + getCurrentScale());
852 | if (currentScale * mScaleFactor <= mMinScale) {//如果超过最小值,则就直接到最小值
853 | finalScale = mMinScale / currentScale;
854 | } else if (currentScale * mScaleFactor >= mMaxScale * 1.5f) {
855 | finalScale = mMaxScale * 1.5f / currentScale;
856 | } else {
857 | finalScale = scaleFactor;
858 | }
859 | return finalScale;
860 | }
861 | }
862 |
863 | private class RotationListener extends RotationGestureDetector.SimpleOnRotationGestureListener {
864 |
865 | @Override
866 | public boolean onRotation(RotationGestureDetector rotationDetector) {
867 | float angle = rotationDetector.getAngle();
868 | if(isHorizontalEnable){
869 | angle = -angle;
870 | }
871 | postRotate(angle, mMidPntX, mMidPntY);
872 | return true;
873 | }
874 | }
875 |
876 |
877 | private class TransformAnimator extends ValueAnimator {
878 | private static final String PROPERTY_NAME_TRANSLATE_X = "TRANSLATE_X";
879 | private static final String PROPERTY_NAME_TRANSLATE_Y = "TRANSLATE_Y";
880 | private static final String PROPERTY_NAME_SCALE_XANDY = "SCALE";
881 |
882 |
883 | private float mLastRote = 0;
884 | private float mLastTranslateX = 0;
885 | private float mLastTranslateY = 0;
886 | private float mLastScale = 1;
887 |
888 | private float getLastScale() {
889 | return mLastScale;
890 | }
891 |
892 | private void setLastScale(float mLastScale) {
893 | this.mLastScale = mLastScale;
894 | }
895 |
896 | private float getLastRote() {
897 | return mLastRote;
898 | }
899 |
900 |
901 | private void setLastRote(float mLastRote) {
902 | this.mLastRote = mLastRote;
903 | }
904 |
905 | private float getLastTraslateX() {
906 | return mLastTranslateX;
907 | }
908 |
909 | private float getLastTraslateY() {
910 | return mLastTranslateY;
911 | }
912 |
913 | private void setLastTraslateX(float mLastTraslateX) {
914 | this.mLastTranslateX = mLastTraslateX;
915 | }
916 |
917 | private void setLastTraslateY(float mLastTraslateY) {
918 | this.mLastTranslateY = mLastTraslateY;
919 | }
920 | }
921 |
922 | }
923 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CropImageLibrary
3 |
4 |
--------------------------------------------------------------------------------
/cropimagelibrary/src/test/java/com/meitu/cropimagelibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.meitu.cropimagelibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Tue Sep 05 20:05:36 CST 2017
16 | systemProp.http.proxyHost=127.0.0.1
17 | org.gradle.jvmargs=-Xmx1536m
18 | systemProp.http.proxyPort=1080
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/waterCode/CropImageProject/65fec159ef6bf7c7333f607e4f63f1d4098e4fdd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 18 10:53:36 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':cropimagelibrary'
2 |
--------------------------------------------------------------------------------