├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── drawable-v24
│ │ │ ├── ic_show.jpg
│ │ │ └── ic_launcher_foreground.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
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── lenny
│ │ └── bezier
│ │ ├── ImageUtil.java
│ │ ├── MainActivity.java
│ │ ├── BaseView.java
│ │ ├── BlurUtil.java
│ │ └── DIYBezierView.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── README.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── local.properties
├── bezier.iml
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='bezier'
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jingyun_breizer
2 | https://juejin.im/post/5df755a85188251260743e49
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | bezier
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_show.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/drawable-v24/ic_show.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuLei0571/jingyun_breizer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 12 16:29:36 CST 2019
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file should *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/Users/liulei/Library/Android/sdk
11 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/bezier.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.1"
6 | defaultConfig {
7 | applicationId "com.lenny.bezier"
8 | minSdkVersion 24
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'androidx.appcompat:appcompat:1.1.0'
25 | implementation 'com.android.support:appcompat-v7:26.1.0'
26 |
27 | implementation 'androidx.palette:palette:1.0.0'
28 | compile 'com.makeramen:roundedimageview:2.2.1'
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
26 |
27 |
33 |
34 |
35 |
36 |
40 |
45 |
48 |
49 |
53 |
62 |
63 |
67 |
68 |
69 |
73 |
74 |
78 |
79 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lenny/bezier/ImageUtil.java:
--------------------------------------------------------------------------------
1 | package com.lenny.bezier;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Rect;
5 | import android.media.MediaMetadataRetriever;
6 | import android.media.ThumbnailUtils;
7 | import android.os.Build;
8 | import android.provider.MediaStore;
9 | import android.view.View;
10 | import android.view.ViewOutlineProvider;
11 |
12 | import java.util.HashMap;
13 |
14 | import androidx.annotation.RequiresApi;
15 | import androidx.palette.graphics.Palette;
16 |
17 |
18 | public class ImageUtil {
19 |
20 | //获取bitmap颜色
21 | public static Palette.Swatch getColor(Bitmap bitmap, int color) {
22 | // Palette的部分
23 | Palette palette = Palette.generate(bitmap);
24 | Palette.Swatch swatche = null;
25 | if (palette != null) {
26 | switch (color) {
27 | case 0:
28 | swatche = palette.getVibrantSwatch();
29 | break;
30 | case 1:
31 | swatche = palette.getLightVibrantSwatch();
32 | break;
33 | case 2:
34 | swatche = palette.getDarkVibrantSwatch();
35 | break;
36 | case 3:
37 | swatche = palette.getMutedSwatch();
38 | break;
39 | case 4:
40 | swatche = palette.getLightMutedSwatch();
41 | break;
42 | case 5:
43 | swatche = palette.getDarkMutedSwatch();
44 | break;
45 | default:
46 | swatche = palette.getVibrantSwatch();
47 | break;
48 | }
49 | if(swatche==null){
50 | swatche = palette.getVibrantSwatch();
51 | }
52 | }
53 | return swatche;
54 | }
55 |
56 |
57 | public static Bitmap createVideoThumbnail(String url, int width, int height) {
58 | Bitmap bitmap = null;
59 | MediaMetadataRetriever retriever = new MediaMetadataRetriever();
60 | int kind = MediaStore.Video.Thumbnails.MINI_KIND;
61 | try {
62 | if (Build.VERSION.SDK_INT >= 14) {
63 | retriever.setDataSource(url, new HashMap());
64 | } else {
65 | retriever.setDataSource(url);
66 | }
67 | bitmap = retriever.getFrameAtTime();
68 | } catch (IllegalArgumentException ex) {
69 | // Assume this is a corrupt video file
70 | } catch (RuntimeException ex) {
71 | // Assume this is a corrupt video file.
72 | } finally {
73 | try {
74 | retriever.release();
75 | } catch (RuntimeException ex) {
76 | // Ignore failures while cleaning up.
77 | }
78 | }
79 | if (kind == MediaStore.Images.Thumbnails.MICRO_KIND && bitmap != null) {
80 | bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
81 | ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
82 | }
83 | return bitmap;
84 | }
85 |
86 |
87 | //设置控件轮廓
88 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
89 | public static ViewOutlineProvider getOutline(boolean b, final int pading, final int circularBead) {
90 | if (b) {
91 | return new ViewOutlineProvider() {
92 | @Override
93 | public void getOutline(View view, android.graphics.Outline outline) {
94 | final int margin = Math.min(view.getWidth(), view.getHeight()) / pading;
95 | outline.setOval(margin, margin, view.getWidth() - margin, view.getHeight() - margin);
96 | }
97 | };
98 | } else {
99 | return new ViewOutlineProvider() {
100 | @Override
101 | public void getOutline(View view, android.graphics.Outline outline) {
102 | final int margin = Math.min(view.getWidth(), view.getHeight()) / pading;
103 | outline.setRoundRect(margin, margin, view.getWidth() - margin, view.getHeight() - margin, circularBead);
104 | }
105 | };
106 | }
107 | }
108 |
109 |
110 | /**
111 | * 裁剪图片
112 | *
113 | * @param rectBitmap
114 | * @param rectSurface
115 | */
116 | public static void centerCrop(Rect rectBitmap, Rect rectSurface) {
117 | int verticalTimes = rectBitmap.height() / rectSurface.height();
118 | int horizontalTimes = rectBitmap.width() / rectSurface.width();
119 | if (verticalTimes > horizontalTimes) {
120 | rectBitmap.left = 0;
121 | rectBitmap.right = rectBitmap.right;
122 | rectBitmap.top = (rectBitmap.height() - (rectSurface.height() * rectBitmap.width() / rectSurface.width())) / 2;
123 | rectBitmap.bottom = rectBitmap.bottom - rectBitmap.top;
124 | } else {
125 | rectBitmap.top = 0;
126 | rectBitmap.bottom = rectBitmap.bottom;
127 | rectBitmap.left = (rectBitmap.width() - (rectSurface.width() * rectBitmap.height() / rectSurface.height())) / 2;
128 | rectBitmap.right = rectBitmap.right - rectBitmap.left;
129 | }
130 |
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lenny/bezier/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lenny.bezier;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.ColorMatrix;
9 | import android.graphics.ColorMatrixColorFilter;
10 | import android.graphics.PointF;
11 | import android.os.Build;
12 | import android.os.Bundle;
13 | import android.util.Log;
14 | import android.view.View;
15 | import android.view.animation.LinearInterpolator;
16 | import android.widget.ImageView;
17 |
18 | import java.util.List;
19 | import java.util.concurrent.Executors;
20 | import java.util.concurrent.ScheduledExecutorService;
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import androidx.annotation.RequiresApi;
24 | import androidx.appcompat.app.AppCompatActivity;
25 |
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | private DIYBezierView diyBezierView;
29 | private DIYBezierView diyBezierView1;
30 | private DIYBezierView diyBezierView2;
31 | private ImageView ivShowPic, iv_bg;
32 | ScheduledExecutorService scheduledExecutorService;
33 |
34 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_main);
39 | iv_bg = findViewById(R.id.iv_bg);
40 | ivShowPic = findViewById(R.id.img_show);
41 |
42 | diyBezierView = findViewById(R.id.circle_bezier_view);
43 |
44 | diyBezierView1 = findViewById(R.id.circle_bezier_view1);
45 | diyBezierView1.setBezierCircleColor(DIYBezierView.NATIVE_CIRCLE_COLOR);
46 | diyBezierView2 = findViewById(R.id.circle_bezier_view2);
47 | diyBezierView2.setBezierCircleColor(DIYBezierView.SEL_POINT_COLOR);
48 |
49 |
50 | diyBezierView.setIsShowHelpLine(true);
51 | scheduledExecutorService = Executors.newScheduledThreadPool(1);
52 | setBackground();
53 | handleRotate();
54 | }
55 |
56 | public void onReset(View view) {
57 | diyBezierView.reset();
58 | diyBezierView1.reset();
59 | diyBezierView2.reset();
60 | scheduledExecutorService.shutdownNow();
61 |
62 | }
63 |
64 | public void onPlay(View view) {
65 |
66 | scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
67 | @Override
68 | public void run() {
69 | diyBezierView.post(new Runnable() {
70 | @Override
71 | public void run() {
72 | diyBezierView.play();
73 | }
74 | });
75 | diyBezierView1.post(new Runnable() {
76 | @Override
77 | public void run() {
78 | diyBezierView1.play();
79 | }
80 | });
81 | diyBezierView2.post(new Runnable() {
82 | @Override
83 | public void run() {
84 | diyBezierView2.play();
85 | }
86 | });
87 | }
88 | }, 0, 80, TimeUnit.MILLISECONDS);
89 |
90 | }
91 |
92 | public void onLog(View view) {
93 | List controlPointList = diyBezierView.getControlPointList();
94 |
95 | StringBuilder stringBuilder = new StringBuilder();
96 | stringBuilder.append("\n");
97 | for (int i = 0; i < controlPointList.size(); ++i) {
98 | stringBuilder.append("第")
99 | .append(i)
100 | .append("个点坐标(单位dp):[")
101 | .append(px2dip(this, controlPointList.get(i).x))
102 | .append(", ")
103 | .append(px2dip(this, controlPointList.get(i).y))
104 | .append("]")
105 | .append("\n");
106 | }
107 |
108 | Log.i("DIY Bezier", "控制点日志: " + stringBuilder.toString());
109 |
110 | }
111 |
112 | public int px2dip(Context context, float pxValue) {
113 | float density = context.getResources().getDisplayMetrics().density;
114 | return (int) (pxValue / density + 0.5f);
115 | }
116 |
117 | public void handleRotate() {
118 | ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(ivShowPic, "rotation", 0f, 360f);
119 | objectAnimator.setDuration(20 * 1000);
120 | objectAnimator.setRepeatMode(ValueAnimator.RESTART);
121 | objectAnimator.setInterpolator(new LinearInterpolator());
122 | objectAnimator.setRepeatCount(-1);
123 | objectAnimator.start();
124 | }
125 |
126 | private void setBackground() {
127 | Bitmap bitmap = BlurUtil.doBlur(BitmapFactory.decodeResource(getResources(), R.drawable.ic_show), 10, 30);
128 | iv_bg.setImageBitmap(bitmap);
129 | iv_bg.setDrawingCacheEnabled(true);
130 | // getBitmap();
131 | int color=ImageUtil.getColor(bitmap, 1).getRgb();
132 | diyBezierView.setBezierCircleColor(color);
133 | int color3=ImageUtil.getColor(bitmap, 3).getRgb();
134 |
135 | diyBezierView1.setBezierCircleColor(color3);
136 | int color5=ImageUtil.getColor(bitmap, 0).getRgb();
137 |
138 | diyBezierView2.setBezierCircleColor(color5);
139 |
140 |
141 | ColorMatrix colorMatrix = new ColorMatrix();
142 | colorMatrix.setScale(0.7f, 0.7f, 0.7f, 1);
143 | ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
144 | iv_bg.setColorFilter(colorFilter);
145 |
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lenny/bezier/BaseView.java:
--------------------------------------------------------------------------------
1 | package com.lenny.bezier;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 | import android.util.DisplayMetrics;
10 | import android.view.View;
11 |
12 | import androidx.annotation.Nullable;
13 |
14 |
15 | public abstract class BaseView extends View {
16 |
17 | protected String TAG = this.getClass().getSimpleName();
18 |
19 | // 坐标画笔
20 | private Paint mCoordinatePaint;
21 | // 网格画笔
22 | private Paint mGridPaint;
23 | // 写字画笔
24 | private Paint mTextPaint;
25 |
26 | // 坐标颜色
27 | private int mCoordinateColor;
28 | private int mGridColor;
29 |
30 | // 网格宽度 50px
31 | private int mGridWidth = 50;
32 |
33 | // 坐标线宽度
34 | private final float mCoordinateLineWidth = 2.5f;
35 | // 网格宽度
36 | private final float mGridLineWidth = 1f;
37 | // 字体大小
38 | private float mTextSize;
39 |
40 | // 标柱的高度
41 | private final float mCoordinateFlagHeight = 8f;
42 |
43 | private boolean _isInit;
44 | protected float mWidth;
45 | protected float mHeight;
46 |
47 | private int mStatusBarHeight;
48 |
49 | public BaseView(Context context) {
50 | this(context, null, 0);
51 | }
52 |
53 | public BaseView(Context context, @Nullable AttributeSet attrs) {
54 | this(context, attrs, 0);
55 | }
56 |
57 | public BaseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | initCoordinate(context);
60 | init(context);
61 | }
62 |
63 | @Override
64 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
65 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
66 | if (!_isInit) {
67 | _isInit = true;
68 |
69 | mWidth = getMeasuredWidth();
70 | mHeight = getMeasuredHeight() + mStatusBarHeight;
71 | }
72 | }
73 |
74 | protected void initCoordinate(Context context) {
75 | mCoordinateColor = Color.BLACK;
76 | mGridColor = Color.LTGRAY;
77 |
78 | mStatusBarHeight = getStatusBarHeight(context);
79 |
80 | mTextSize = sp2px(context, 10);
81 |
82 | mCoordinatePaint = new Paint();
83 | mCoordinatePaint.setAntiAlias(true);
84 | mCoordinatePaint.setColor(mCoordinateColor);
85 | mCoordinatePaint.setStrokeWidth(mCoordinateLineWidth);
86 |
87 | mGridPaint = new Paint();
88 | mGridPaint.setAntiAlias(true);
89 | mGridPaint.setColor(mGridColor);
90 | mGridPaint.setStrokeWidth(mGridLineWidth);
91 |
92 | mTextPaint = new Paint();
93 | mTextPaint.setAntiAlias(true);
94 | mTextPaint.setColor(mCoordinateColor);
95 | mTextPaint.setTextAlign(Paint.Align.CENTER);
96 | mTextPaint.setTextSize(mTextSize);
97 | }
98 |
99 | protected abstract void init(Context context);
100 |
101 | /**
102 | * 画坐标和网格,以画布中心点为原点
103 | *
104 | * @param canvas 画布
105 | */
106 | protected void drawCoordinate(Canvas canvas) {
107 |
108 | float halfWidth = mWidth / 2;
109 | float halfHeight = mHeight / 2;
110 |
111 | // 画网格
112 | canvas.save();
113 | canvas.translate(halfWidth, halfHeight);
114 | int curWidth = mGridWidth;
115 | // 画横线
116 | while (curWidth < halfWidth + mGridWidth) {
117 |
118 | // 向右画
119 | canvas.drawLine(curWidth, -halfHeight, curWidth, halfHeight, mGridPaint);
120 | // 向左画
121 | canvas.drawLine(-curWidth, -halfHeight, -curWidth, halfHeight, mGridPaint);
122 |
123 | // 画标柱
124 | canvas.drawLine(curWidth, 0, curWidth, -mCoordinateFlagHeight, mCoordinatePaint);
125 | canvas.drawLine(-curWidth, 0, -curWidth, -mCoordinateFlagHeight, mCoordinatePaint);
126 |
127 | // 标柱宽度(每两个画一个)
128 | if (curWidth % (mGridWidth * 2) == 0) {
129 | canvas.drawText(curWidth + "", curWidth, mTextSize * 1.5f, mTextPaint);
130 | canvas.drawText(-curWidth + "", -curWidth, mTextSize * 1.5f, mTextPaint);
131 | }
132 |
133 | curWidth += mGridWidth;
134 | }
135 |
136 | int curHeight = mGridWidth;
137 | // 画竖线
138 | while (curHeight < halfHeight + mGridWidth) {
139 |
140 | // 向右画
141 | canvas.drawLine(-halfWidth, curHeight, halfWidth, curHeight, mGridPaint);
142 | // 向左画
143 | canvas.drawLine(-halfWidth, -curHeight, halfWidth, -curHeight, mGridPaint);
144 |
145 | // 画标柱
146 | canvas.drawLine(0, curHeight, mCoordinateFlagHeight, curHeight, mCoordinatePaint);
147 | canvas.drawLine(0, -curHeight, mCoordinateFlagHeight, -curHeight, mCoordinatePaint);
148 |
149 | // 标柱宽度(每两个画一个)
150 | if (curHeight % (mGridWidth * 2) == 0) {
151 | canvas.drawText(curHeight + "", -mTextSize * 2, curHeight + mTextSize / 2, mTextPaint);
152 | canvas.drawText(-curHeight + "", -mTextSize * 2, -curHeight + mTextSize / 2, mTextPaint);
153 | }
154 |
155 | curHeight += mGridWidth;
156 | }
157 | canvas.restore();
158 |
159 | // 画 x,y 轴
160 | canvas.drawLine(halfWidth, 0, halfWidth, mHeight, mCoordinatePaint);
161 | canvas.drawLine(0, halfHeight, mWidth, halfHeight, mCoordinatePaint);
162 |
163 | }
164 |
165 | protected int sp2px(Context context, float spValue) {
166 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
167 | return (int) (spValue * fontScale + 0.5f);
168 | }
169 |
170 | /**
171 | * 转换 dp 至 px
172 | *
173 | * @param dp dp像素
174 | * @return
175 | */
176 | protected int dpToPx(float dp) {
177 | DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
178 | return (int) (dp * metrics.density + 0.5f);
179 | }
180 |
181 | protected int getStatusBarHeight(Context context) {
182 | int result = 0;
183 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
184 | if (resourceId > 0) {
185 | result = context.getResources().getDimensionPixelSize(resourceId);
186 | }
187 | return result;
188 | }
189 | }
190 |
191 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lenny/bezier/BlurUtil.java:
--------------------------------------------------------------------------------
1 | package com.lenny.bezier;
2 |
3 | import android.graphics.Bitmap;
4 |
5 |
6 | public class BlurUtil {
7 | private static final String TAG = BlurUtil.class.getSimpleName();
8 |
9 | /**
10 | * 对图片进行毛玻璃化
11 | *
12 | * @param sentBitmap 位图
13 | * @param radius 虚化程度
14 | * @param canReuseInBitmap 是否重用
15 | * @return 位图
16 | */
17 | public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
18 | // Stack Blur v1.0 from
19 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
20 | //
21 | // Java Author: Mario Klingemann
22 | // http://incubator.quasimondo.com
23 | // created Feburary 29, 2004
24 | // Android port : Yahel Bouaziz
25 | // http://www.kayenko.com
26 | // ported april 5th, 2012
27 | // This is a compromise between Gaussian Blur and Box blur
28 | // It creates much better looking blurs than Box Blur, but is
29 | // 7x faster than my Gaussian Blur implementation.
30 | //
31 | // I called it Stack Blur because this describes best how this
32 | // filter works internally: it creates a kind of moving stack
33 | // of colors whilst scanning through the image. Thereby it
34 | // just has to add one new block of color to the right side
35 | // of the stack and remove the leftmost color. The remaining
36 | // colors on the topmost layer of the stack are either added on
37 | // or reduced by one, depending on if they are on the right or
38 | // on the left side of the stack.
39 | //
40 | // If you are using this algorithm in your code please add
41 | // the following line:
42 | //
43 | // Stack Blur Algorithm by Mario Klingemann
44 | Bitmap bitmap;
45 | if (canReuseInBitmap) {
46 | bitmap = sentBitmap;
47 | } else {
48 | bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
49 | }
50 | if (radius < 1) {
51 | return (null);
52 | }
53 | int w = bitmap.getWidth();
54 | int h = bitmap.getHeight();
55 | int[] pix = new int[w * h];
56 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
57 | int wm = w - 1;
58 | int hm = h - 1;
59 | int wh = w * h;
60 | int div = radius + radius + 1;
61 | int r[] = new int[wh];
62 | int g[] = new int[wh];
63 | int b[] = new int[wh];
64 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
65 | int vmin[] = new int[Math.max(w, h)];
66 | int divsum = (div + 1) >> 1;
67 | divsum *= divsum;
68 | int dv[] = new int[256 * divsum];
69 | for (i = 0; i < 256 * divsum; i++) {
70 | dv[i] = (i / divsum);
71 | }
72 | yw = yi = 0;
73 | int[][] stack = new int[div][3];
74 | int stackpointer;
75 | int stackstart;
76 | int[] sir;
77 | int rbs;
78 | int r1 = radius + 1;
79 | int routsum, goutsum, boutsum;
80 | int rinsum, ginsum, binsum;
81 | for (y = 0; y < h; y++) {
82 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
83 | for (i = -radius; i <= radius; i++) {
84 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
85 | sir = stack[i + radius];
86 | sir[0] = (p & 0xff0000) >> 16;
87 | sir[1] = (p & 0x00ff00) >> 8;
88 | sir[2] = (p & 0x0000ff);
89 | rbs = r1 - Math.abs(i);
90 | rsum += sir[0] * rbs;
91 | gsum += sir[1] * rbs;
92 | bsum += sir[2] * rbs;
93 | if (i > 0) {
94 | rinsum += sir[0];
95 | ginsum += sir[1];
96 | binsum += sir[2];
97 | } else {
98 | routsum += sir[0];
99 | goutsum += sir[1];
100 | boutsum += sir[2];
101 | }
102 | }
103 | stackpointer = radius;
104 | for (x = 0; x < w; x++) {
105 | r[yi] = dv[rsum];
106 | g[yi] = dv[gsum];
107 | b[yi] = dv[bsum];
108 | rsum -= routsum;
109 | gsum -= goutsum;
110 | bsum -= boutsum;
111 | stackstart = stackpointer - radius + div;
112 | sir = stack[stackstart % div];
113 | routsum -= sir[0];
114 | goutsum -= sir[1];
115 | boutsum -= sir[2];
116 | if (y == 0) {
117 | vmin[x] = Math.min(x + radius + 1, wm);
118 | }
119 | p = pix[yw + vmin[x]];
120 | sir[0] = (p & 0xff0000) >> 16;
121 | sir[1] = (p & 0x00ff00) >> 8;
122 | sir[2] = (p & 0x0000ff);
123 | rinsum += sir[0];
124 | ginsum += sir[1];
125 | binsum += sir[2];
126 | rsum += rinsum;
127 | gsum += ginsum;
128 | bsum += binsum;
129 | stackpointer = (stackpointer + 1) % div;
130 | sir = stack[(stackpointer) % div];
131 | routsum += sir[0];
132 | goutsum += sir[1];
133 | boutsum += sir[2];
134 | rinsum -= sir[0];
135 | ginsum -= sir[1];
136 | binsum -= sir[2];
137 | yi++;
138 | }
139 | yw += w;
140 | }
141 | for (x = 0; x < w; x++) {
142 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
143 | yp = -radius * w;
144 | for (i = -radius; i <= radius; i++) {
145 | yi = Math.max(0, yp) + x;
146 | sir = stack[i + radius];
147 | sir[0] = r[yi];
148 | sir[1] = g[yi];
149 | sir[2] = b[yi];
150 | rbs = r1 - Math.abs(i);
151 | rsum += r[yi] * rbs;
152 | gsum += g[yi] * rbs;
153 | bsum += b[yi] * rbs;
154 | if (i > 0) {
155 | rinsum += sir[0];
156 | ginsum += sir[1];
157 | binsum += sir[2];
158 | } else {
159 | routsum += sir[0];
160 | goutsum += sir[1];
161 | boutsum += sir[2];
162 | }
163 | if (i < hm) {
164 | yp += w;
165 | }
166 | }
167 | yi = x;
168 | stackpointer = radius;
169 | for (y = 0; y < h; y++) {
170 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
171 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
172 | rsum -= routsum;
173 | gsum -= goutsum;
174 | bsum -= boutsum;
175 | stackstart = stackpointer - radius + div;
176 | sir = stack[stackstart % div];
177 | routsum -= sir[0];
178 | goutsum -= sir[1];
179 | boutsum -= sir[2];
180 | if (x == 0) {
181 | vmin[y] = Math.min(y + r1, hm) * w;
182 | }
183 | p = x + vmin[y];
184 | sir[0] = r[p];
185 | sir[1] = g[p];
186 | sir[2] = b[p];
187 | rinsum += sir[0];
188 | ginsum += sir[1];
189 | binsum += sir[2];
190 | rsum += rinsum;
191 | gsum += ginsum;
192 | bsum += binsum;
193 | stackpointer = (stackpointer + 1) % div;
194 | sir = stack[stackpointer];
195 | routsum += sir[0];
196 | goutsum += sir[1];
197 | boutsum += sir[2];
198 | rinsum -= sir[0];
199 | ginsum -= sir[1];
200 | binsum -= sir[2];
201 | yi += w;
202 | }
203 | }
204 | bitmap.setPixels(pix, 0, w, 0, 0, w, h);
205 | // print("虚化后 ",bitmap);
206 | return (bitmap);
207 | }
208 |
209 | /**
210 | * 对图片进行毛玻璃化
211 | *
212 | * @param originBitmap 位图
213 | * @param scaleRatio 缩放比率
214 | * @param blurRadius 毛玻璃化比率,虚化程度
215 | * @return 位图
216 | */
217 | public static Bitmap doBlur(Bitmap originBitmap, int scaleRatio, int blurRadius) {
218 | // print("原图::",originBitmap);
219 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap,
220 | originBitmap.getWidth() / scaleRatio,
221 | originBitmap.getHeight() / scaleRatio,
222 | false);
223 | Bitmap blurBitmap = doBlur(scaledBitmap, blurRadius, false);
224 | scaledBitmap.recycle();
225 | return blurBitmap;
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lenny/bezier/DIYBezierView.java:
--------------------------------------------------------------------------------
1 | package com.lenny.bezier;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PointF;
9 | import android.graphics.RectF;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import androidx.annotation.Nullable;
17 |
18 |
19 | public class DIYBezierView extends BaseView {
20 |
21 | public static final String BEZIER_CIRCLE_COLOR = "#1296db"; //绿色
22 | public static final String NATIVE_CIRCLE_COLOR = "#1296db"; //橙色
23 | public static final String SEL_POINT_COLOR = "#1296db"; //蓝色
24 |
25 | // 圆的中心点
26 | private PointF mCenterPoint;
27 | // 圆半径
28 | private float mRadius;
29 |
30 | // 控制点列表,顺序为:右上、右下、左下、左上
31 | private List mControlPointList;
32 |
33 | // 选中的点集合,受 status 影响
34 | private final List mCurSelectPointList = new ArrayList<>();
35 |
36 | // 控制点占半径的比例
37 | private float mRatio;
38 |
39 | private Path mPath;
40 |
41 |
42 | private Paint mPaint;
43 |
44 | // 有效触碰的范围
45 | private int mTouchRegionWidth;
46 |
47 |
48 | // 是否显示辅助线
49 | private boolean mIsShowHelpLine;
50 |
51 | // 触碰的x轴
52 | private float mLastX = -1;
53 | // 触碰的y轴
54 | private float mLastY = -1;
55 |
56 | public DIYBezierView(Context context) {
57 | super(context);
58 | }
59 |
60 | public DIYBezierView(Context context, @Nullable AttributeSet attrs) {
61 | super(context, attrs);
62 | }
63 |
64 | public DIYBezierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
65 | super(context, attrs, defStyleAttr);
66 | }
67 |
68 | /**
69 | * 获取控制点
70 | *
71 | * @return
72 | */
73 | public List getControlPointList() {
74 | return mControlPointList;
75 | }
76 |
77 |
78 | public void setIsShowHelpLine(boolean isShowHelpLine) {
79 | this.mIsShowHelpLine = isShowHelpLine;
80 | invalidate();
81 | }
82 |
83 | @Override
84 | protected void init(Context context) {
85 | int width = context.getResources().getDisplayMetrics().widthPixels;
86 | mRadius = width / 4;
87 |
88 | // LINE_WIDTH = dpToPx(2);
89 | // POINT_RADIO_WIDTH = dpToPx(4);
90 | // SEL_POINT_RADIO_WIDTH = dpToPx(6);
91 | mTouchRegionWidth = dpToPx(20);
92 |
93 | mCenterPoint = new PointF(0, 0);
94 |
95 | mControlPointList = new ArrayList<>();
96 |
97 | mPath = new Path();
98 |
99 | mPaint = new Paint();
100 | mPaint.setAntiAlias(true);
101 | mPaint.setStyle(Paint.Style.STROKE);
102 | mPaint.setStrokeWidth(4);
103 | mPaint.setAlpha(200);
104 | mPaint.setColor(Color.parseColor(BEZIER_CIRCLE_COLOR));
105 | // mPaint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
106 |
107 | mIsShowHelpLine = true;
108 |
109 | mRatio = 0.55f;
110 |
111 | calculateControlPoint();
112 | }
113 |
114 | public void setBezierCircleColor(int color){
115 | mPaint.setColor(color);
116 | }
117 | public void setBezierCircleColor(String color) {
118 | mPaint.setColor(Color.parseColor(color));
119 | }
120 |
121 | public void reset() {
122 | calculateControlPoint();
123 | invalidate();
124 | }
125 |
126 | public void play() {
127 | calculateControlPointPlay();
128 | invalidate();
129 | }
130 |
131 | @Override
132 | protected void onDraw(Canvas canvas) {
133 | // drawCoordinate(canvas);
134 |
135 | canvas.translate(mWidth / 2, mHeight / 2);
136 |
137 | mPath.reset();
138 |
139 | // 画圆
140 | for (int i = 0; i < 4; i++) {
141 | if (i == 0) {
142 | mPath.moveTo(mControlPointList.get(i * 3).x, mControlPointList.get(i * 3).y);
143 | } else {
144 | mPath.lineTo(mControlPointList.get(i * 3).x, mControlPointList.get(i * 3).y);
145 | }
146 |
147 | int endPointIndex;
148 | if (i == 3) {
149 | endPointIndex = 0;
150 | } else {
151 | endPointIndex = i * 3 + 3;
152 | }
153 |
154 | mPath.cubicTo(mControlPointList.get(i * 3 + 1).x, mControlPointList.get(i * 3 + 1).y,
155 | mControlPointList.get(i * 3 + 2).x, mControlPointList.get(i * 3 + 2).y,
156 | mControlPointList.get(endPointIndex).x, mControlPointList.get(endPointIndex).y);
157 | }
158 | // 绘制贝塞尔曲线
159 | canvas.drawPath(mPath, mPaint);
160 |
161 | // 不需要辅助线,则画完贝塞尔曲线就终止
162 | if (!mIsShowHelpLine) {
163 | return;
164 | }
165 |
166 | }
167 |
168 | @Override
169 | public boolean onTouchEvent(MotionEvent event) {
170 |
171 | // 触碰的坐标
172 | float x = event.getX();
173 | float y = event.getY();
174 |
175 | switch (event.getAction()) {
176 | case MotionEvent.ACTION_DOWN:
177 | if (selectControlPoint(x, y)) {
178 | mLastX = x;
179 | mLastY = y;
180 | }
181 |
182 | break;
183 | case MotionEvent.ACTION_MOVE:
184 | if (mLastX == -1 || mLastY == -1) {
185 | return true;
186 | }
187 |
188 | // 计算偏移值
189 | float offsetX = x - mLastX;
190 | float offsetY = y - mLastY;
191 |
192 | for (PointF point : mCurSelectPointList) {
193 | point.x = point.x + offsetX;
194 | point.y = point.y + offsetY;
195 | }
196 | // }
197 |
198 |
199 | mLastX = x;
200 | mLastY = y;
201 |
202 | break;
203 | case MotionEvent.ACTION_UP:
204 | mCurSelectPointList.clear();
205 | // mSelPoint = null;
206 | mLastX = -1;
207 | mLastY = -1;
208 | break;
209 | default:
210 | break;
211 | }
212 |
213 | invalidate();
214 |
215 | return true;
216 | }
217 |
218 | /**
219 | * 是否在有效的触碰范围
220 | *
221 | * @param x
222 | * @param y
223 | * @return true 有选中;false 无选中
224 | */
225 | private boolean selectControlPoint(float x, float y) {
226 |
227 | // 选中的下标
228 | int selIndex = -1;
229 |
230 | for (int i = 0; i < mControlPointList.size(); ++i) {
231 |
232 | PointF controlPoint = mControlPointList.get(i);
233 |
234 | float resultX = controlPoint.x + mWidth / 2;
235 | float resultY = controlPoint.y + mHeight / 2;
236 |
237 | RectF pointRange = new RectF(resultX - mTouchRegionWidth + 2,
238 | resultY - mTouchRegionWidth,
239 | resultX + mTouchRegionWidth,
240 | resultY + mTouchRegionWidth);
241 |
242 | if (pointRange.contains(x, y)) {
243 | selIndex = i;
244 | break;
245 | }
246 | }
247 |
248 | // 如果没有选中的就返回
249 | if (selIndex == -1) {
250 | return false;
251 | }
252 |
253 | // 清空之前的选中点
254 | mCurSelectPointList.clear();
255 |
256 | // mSelPoint = mControlPointList.get(selIndex);
257 |
258 | mCurSelectPointList.add(mControlPointList.get(selIndex));
259 |
260 | return true;
261 |
262 | }
263 |
264 | /**
265 | * 计算圆的控制点
266 | */
267 | private void calculateControlPoint() {
268 | // 计算 中间控制点到端点的距离
269 | float controlWidth = mRatio * mRadius;
270 |
271 | mControlPointList.clear();
272 |
273 | // 右上
274 | mControlPointList.add(new PointF(0, -mRadius));//
275 | mControlPointList.add(new PointF(controlWidth, -mRadius));
276 | mControlPointList.add(new PointF(mRadius, -controlWidth));
277 |
278 | // 右下
279 | mControlPointList.add(new PointF(mRadius, 0));
280 | mControlPointList.add(new PointF(mRadius, controlWidth));
281 | mControlPointList.add(new PointF(controlWidth, mRadius));
282 |
283 | // 左下
284 | mControlPointList.add(new PointF(0, mRadius));
285 | mControlPointList.add(new PointF(-controlWidth, mRadius));
286 | mControlPointList.add(new PointF(-mRadius, controlWidth));
287 | // 左上
288 | mControlPointList.add(new PointF(-mRadius, 0));
289 | mControlPointList.add(new PointF(-mRadius, -controlWidth));
290 | mControlPointList.add(new PointF(-controlWidth, -mRadius));
291 |
292 | }
293 |
294 |
295 | /**
296 | * 计算圆的控制点
297 | */
298 | private void calculateControlPointPlay() {
299 | // 计算 中间控制点到端点的距离
300 | float controlWidth = mRatio * mRadius;
301 |
302 | mControlPointList.clear();
303 |
304 |
305 | // 右上
306 | mControlPointList.add(new PointF((float) (Math.random() * 30), (float) (-mRadius - (Math.random() * 30))));//
307 | mControlPointList.add(new PointF((float) (controlWidth + Math.random() * 100), -mRadius));
308 | mControlPointList.add(new PointF((float) (mRadius + Math.random() * 50), -controlWidth));
309 |
310 | // 右下
311 | mControlPointList.add(new PointF((float) (Math.random() *30) + mRadius, 0));
312 | mControlPointList.add(new PointF((float) (mRadius + Math.random() * 60), controlWidth));
313 | mControlPointList.add(new PointF(controlWidth, (float) (mRadius + Math.random() * 70)));
314 |
315 | // 左下
316 | mControlPointList.add(new PointF((float) (Math.random() * 30), (float) (mRadius + (Math.random() * 30))));
317 | mControlPointList.add(new PointF((float) (-controlWidth - Math.random() * 100), mRadius));
318 | mControlPointList.add(new PointF(-mRadius, (float) (controlWidth + Math.random() * 100)));
319 | // 左上
320 | mControlPointList.add(new PointF(-mRadius - (float) (Math.random() * 40), (float) (Math.random() * 40)));
321 | mControlPointList.add(new PointF((float) (-mRadius - Math.random() * 110), -controlWidth));
322 | mControlPointList.add(new PointF(-controlWidth, (float) (-mRadius - Math.random() * 150)));
323 |
324 | }
325 |
326 | }
327 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | generateDebugSources
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------