├── app
├── .gitignore
├── screenshot
│ └── BeautyImage.gif
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── icon.png
│ │ │ │ ├── test.png
│ │ │ │ ├── wsc.jpeg
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── 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-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_matrix_two.xml
│ │ │ │ ├── activity_beauty_four.xml
│ │ │ │ ├── item_recyclerview_image.xml
│ │ │ │ ├── activity_beauty_three.xml
│ │ │ │ ├── activity_beauty.xml
│ │ │ │ ├── activity_beauty_two.xml
│ │ │ │ ├── activity_matrix_one.xml
│ │ │ │ └── activity_beauty_one.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lcw
│ │ │ │ └── beauty
│ │ │ │ ├── demo2
│ │ │ │ ├── MatrixActivity.java
│ │ │ │ ├── MatrixSkewView.java
│ │ │ │ ├── MatrixRotateView.java
│ │ │ │ ├── MatrixScaleView.java
│ │ │ │ ├── MatrixTranslateView.java
│ │ │ │ └── MatrixView.java
│ │ │ │ ├── demo1
│ │ │ │ ├── BeautyActivityThree.java
│ │ │ │ ├── BeautyActivityOne.java
│ │ │ │ ├── BeautyActivityTwo.java
│ │ │ │ ├── BeautyActivityFour.java
│ │ │ │ └── BeautyUtil.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── lcw
│ │ │ └── beauty
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lcw
│ │ └── beauty
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── compiler.xml
├── modules.xml
├── runConfigurations.xml
├── misc.xml
└── codeStyles
│ └── Project.xml
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/screenshot/BeautyImage.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/screenshot/BeautyImage.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BeautyImageDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxhdpi/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxhdpi/test.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/wsc.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxhdpi/wsc.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lichenwei-Dev/BeautyImageDemo/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/Lichenwei-Dev/BeautyImageDemo/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/Lichenwei-Dev/BeautyImageDemo/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/Lichenwei-Dev/BeautyImageDemo/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/Lichenwei-Dev/BeautyImageDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #3F51B5
5 | #3F51B5
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android开发之图像处理那点事——滤镜
2 |
3 | 具体参考博客:[Android开发之图像处理那点事——滤镜](https://www.jianshu.com/p/0a291bdf72c2)
4 |
5 | #### 演示效果图:
6 | 
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 08 22:13:00 CST 2018
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.4-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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/lcw/beauty/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_matrix_two.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_beauty_four.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixActivity.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.lcw.beauty.R;
8 |
9 | /**
10 | * Create by: chenWei.li
11 | * Date: 2018/11/16
12 | * Time: 下午10:18
13 | * Email: lichenwei.me@foxmail.com
14 | */
15 | public class MatrixActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_matrix_two);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recyclerview_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_beauty_three.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.lcw.beauty"
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support:recyclerview-v7:27.1.1'
25 | }
26 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/lcw/beauty/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.lcw.beauty", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo1/BeautyActivityThree.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo1;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.ImageView;
8 |
9 | import com.lcw.beauty.R;
10 |
11 | /**
12 | * 更改像素点RGBA效果
13 | */
14 | public class BeautyActivityThree extends AppCompatActivity {
15 |
16 | private ImageView mImageView;
17 |
18 | private Bitmap mBitmap;
19 |
20 | @Override
21 |
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_beauty_three);
25 | mImageView = findViewById(R.id.imageView);
26 |
27 | mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.test);
28 | Bitmap bitmap=BeautyUtil.beautyImage(mBitmap);
29 |
30 | mImageView.setImageBitmap(bitmap);
31 |
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_beauty.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
30 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_beauty_two.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
24 |
25 |
29 |
30 |
36 |
37 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixSkewView.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.lcw.beauty.R;
13 |
14 | /**
15 | * 图像的错切
16 | * Create by: chenWei.li
17 | * Date: 2018/11/16
18 | * Time: 下午11:56
19 | * Email: lichenwei.me@foxmail.com
20 | */
21 | public class MatrixSkewView extends View {
22 |
23 | private Bitmap mBitmap;
24 |
25 | public MatrixSkewView(Context context) {
26 | super(context);
27 | initView(context);
28 | }
29 |
30 | public MatrixSkewView(Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | initView(context);
33 | }
34 |
35 | public MatrixSkewView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | initView(context);
38 | }
39 |
40 | private void initView(Context context) {
41 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | if (mBitmap != null) {
47 | canvas.drawBitmap(mBitmap, 0, 0, null);
48 |
49 | Matrix matrix = new Matrix();
50 | matrix.setSkew(2, 2);
51 | canvas.drawBitmap(mBitmap, matrix, null);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixRotateView.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.lcw.beauty.R;
13 |
14 | /**
15 | * 图像的旋转
16 | * Create by: chenWei.li
17 | * Date: 2018/11/16
18 | * Time: 下午11:56
19 | * Email: lichenwei.me@foxmail.com
20 | */
21 | public class MatrixRotateView extends View {
22 |
23 | private Bitmap mBitmap;
24 |
25 | public MatrixRotateView(Context context) {
26 | super(context);
27 | initView(context);
28 | }
29 |
30 | public MatrixRotateView(Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | initView(context);
33 | }
34 |
35 | public MatrixRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | initView(context);
38 | }
39 |
40 | private void initView(Context context) {
41 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | if (mBitmap != null) {
47 | canvas.drawBitmap(mBitmap, 0, 0, null);
48 |
49 | Matrix matrix = new Matrix();
50 | matrix.setRotate(20);
51 | canvas.drawBitmap(mBitmap, matrix, null);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixScaleView.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.lcw.beauty.R;
13 |
14 | /**
15 | * 图像的缩放
16 | * Create by: chenWei.li
17 | * Date: 2018/11/16
18 | * Time: 下午11:56
19 | * Email: lichenwei.me@foxmail.com
20 | */
21 | public class MatrixScaleView extends View {
22 |
23 | private Bitmap mBitmap;
24 |
25 | public MatrixScaleView(Context context) {
26 | super(context);
27 | initView(context);
28 | }
29 |
30 | public MatrixScaleView(Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | initView(context);
33 | }
34 |
35 | public MatrixScaleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | initView(context);
38 | }
39 |
40 | private void initView(Context context) {
41 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | if (mBitmap != null) {
47 |
48 | canvas.drawBitmap(mBitmap, 0, 0, null);
49 |
50 | Matrix matrix = new Matrix();
51 | matrix.setScale(2, 2);
52 | canvas.drawBitmap(mBitmap, matrix, null);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixTranslateView.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.lcw.beauty.R;
13 |
14 | /**
15 | * 图像的平移
16 | * Create by: chenWei.li
17 | * Date: 2018/11/16
18 | * Time: 下午11:56
19 | * Email: lichenwei.me@foxmail.com
20 | */
21 | public class MatrixTranslateView extends View {
22 |
23 | private Bitmap mBitmap;
24 |
25 | public MatrixTranslateView(Context context) {
26 | super(context);
27 | initView(context);
28 | }
29 |
30 | public MatrixTranslateView(Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | initView(context);
33 | }
34 |
35 | public MatrixTranslateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | initView(context);
38 | }
39 |
40 | private void initView(Context context) {
41 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | if (mBitmap != null) {
47 | canvas.drawBitmap(mBitmap, 0, 0, null);
48 |
49 | Matrix matrix = new Matrix();
50 | matrix.setTranslate(50, 50);
51 | canvas.drawBitmap(mBitmap, matrix, null);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo2/MatrixView.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo2;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.lcw.beauty.R;
13 |
14 | /**
15 | * 图像的变换演示
16 | * Create by: chenWei.li
17 | * Date: 2018/11/16
18 | * Time: 下午11:56
19 | * Email: lichenwei.me@foxmail.com
20 | */
21 | public class MatrixView extends View {
22 |
23 | private Bitmap mBitmap;
24 |
25 | public MatrixView(Context context) {
26 | super(context);
27 | initView(context);
28 | }
29 |
30 | public MatrixView(Context context, @Nullable AttributeSet attrs) {
31 | super(context, attrs);
32 | initView(context);
33 | }
34 |
35 | public MatrixView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | initView(context);
38 | }
39 |
40 | private void initView(Context context) {
41 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon);
42 | }
43 |
44 | @Override
45 | protected void onDraw(Canvas canvas) {
46 | if (mBitmap != null) {
47 | canvas.drawBitmap(mBitmap, 0, 0, null);
48 |
49 | Matrix matrix = new Matrix();
50 | matrix.setTranslate(200, 200);
51 | matrix.preScale(2, 2);
52 | matrix.preRotate(20);
53 | canvas.drawBitmap(mBitmap, matrix, null);
54 |
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/.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 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_matrix_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
20 |
21 |
26 |
27 |
28 |
29 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.lcw.beauty.demo1.BeautyActivityFour;
9 | import com.lcw.beauty.demo1.BeautyActivityOne;
10 | import com.lcw.beauty.demo1.BeautyActivityThree;
11 | import com.lcw.beauty.demo1.BeautyActivityTwo;
12 |
13 | /**
14 | * Create by: chenWei.li
15 | * Date: 2018/11/11
16 | * Time: 上午11:29
17 | * Email: lichenwei.me@foxmail.com
18 | */
19 | public class MainActivity extends AppCompatActivity {
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_beauty);
24 |
25 | findViewById(R.id.btn_One).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View v) {
28 | startActivity(new Intent(MainActivity.this, BeautyActivityOne.class));
29 | }
30 | });
31 |
32 | findViewById(R.id.btn_Two).setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | startActivity(new Intent(MainActivity.this, BeautyActivityTwo.class));
36 | }
37 | });
38 |
39 | findViewById(R.id.btn_Three).setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | startActivity(new Intent(MainActivity.this, BeautyActivityThree.class));
43 | }
44 | });
45 |
46 | findViewById(R.id.btn_Four).setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | startActivity(new Intent(MainActivity.this, BeautyActivityFour.class));
50 | }
51 | });
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/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_beauty_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
25 |
26 |
31 |
32 |
37 |
38 |
39 |
46 |
47 |
52 |
53 |
58 |
59 |
60 |
67 |
68 |
73 |
74 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo1/BeautyActivityOne.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo1;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.AppCompatSeekBar;
8 | import android.widget.ImageView;
9 | import android.widget.SeekBar;
10 |
11 | import com.lcw.beauty.R;
12 |
13 | /**
14 | * ColorMatrix效果演示
15 | */
16 | public class BeautyActivityOne extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
17 |
18 | private ImageView mImageView;
19 | private AppCompatSeekBar mRotateSeekBar;
20 | private AppCompatSeekBar mSaturationSeekBar;
21 | private AppCompatSeekBar mScaleSeekBar;
22 |
23 |
24 | private Bitmap mBitmap;
25 | private float mRotate;
26 | private float mSaturation;
27 | private float mScale;
28 |
29 | private static int MIN_PROGRESS = 128;
30 | private static int MAX_PROGRESS = 255;
31 |
32 | @Override
33 |
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_beauty_one);
37 |
38 | mImageView = findViewById(R.id.imageView);
39 | mRotateSeekBar = findViewById(R.id.seekBar_rotate);
40 | mSaturationSeekBar = findViewById(R.id.seekBar_saturation);
41 | mScaleSeekBar = findViewById(R.id.seekBar_scale);
42 |
43 | mRotateSeekBar.setOnSeekBarChangeListener(this);
44 | mSaturationSeekBar.setOnSeekBarChangeListener(this);
45 | mScaleSeekBar.setOnSeekBarChangeListener(this);
46 |
47 | mRotateSeekBar.setMax(MAX_PROGRESS);
48 | mSaturationSeekBar.setMax(MAX_PROGRESS);
49 | mScaleSeekBar.setMax(MAX_PROGRESS);
50 |
51 | mRotateSeekBar.setProgress(MIN_PROGRESS);
52 | mSaturationSeekBar.setProgress(MIN_PROGRESS);
53 | mScaleSeekBar.setProgress(MIN_PROGRESS);
54 |
55 |
56 | mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.test);
57 |
58 | }
59 |
60 | @Override
61 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
62 | switch (seekBar.getId()) {
63 | case R.id.seekBar_rotate:
64 | mRotate = (mRotateSeekBar.getProgress() - 128f) * 1.0f / 128f * 180;
65 | break;
66 | case R.id.seekBar_saturation:
67 | mSaturation = mSaturationSeekBar.getProgress() / 128f;
68 | break;
69 | case R.id.seekBar_scale:
70 | mScale = mScaleSeekBar.getProgress() / 128f;
71 | break;
72 | }
73 |
74 | if (mBitmap != null) {
75 | Bitmap bitmap = BeautyUtil.beautyImage(mBitmap, mRotate, mSaturation, mScale);
76 | mImageView.setImageBitmap(bitmap);
77 | }
78 |
79 | }
80 |
81 | @Override
82 | public void onStartTrackingTouch(SeekBar seekBar) {
83 |
84 | }
85 |
86 | @Override
87 | public void onStopTrackingTouch(SeekBar seekBar) {
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo1/BeautyActivityTwo.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo1;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.ColorMatrix;
6 | import android.graphics.ColorMatrixColorFilter;
7 | import android.os.Bundle;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.GridLayout;
14 | import android.widget.ImageView;
15 |
16 | import com.lcw.beauty.R;
17 |
18 | /**
19 | * 改变色调原理演示
20 | */
21 | public class BeautyActivityTwo extends AppCompatActivity {
22 |
23 | private ImageView mImageView;
24 | private GridLayout mGridLayout;
25 | private Button mBtnOk;
26 | private Button mBtnReset;
27 |
28 | private Bitmap mBitmap;
29 |
30 | private EditText mEditTexts[] = new EditText[20];
31 | private float[] mColorMatrix = new float[20];
32 |
33 | @Override
34 |
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_beauty_two);
38 |
39 | mImageView = findViewById(R.id.imageView);
40 | mGridLayout = findViewById(R.id.gridLayout);
41 | mBtnOk = findViewById(R.id.btnOk);
42 | mBtnReset = findViewById(R.id.btnReset);
43 | mGridLayout.post(new Runnable() {
44 | @Override
45 | public void run() {
46 | for (int i = 0; i < 20; i++) {
47 | EditText editText = new EditText(BeautyActivityTwo.this);
48 | editText.setGravity(Gravity.CENTER);
49 | if (i % 6 == 0) {
50 | editText.setText("1");
51 | } else {
52 | editText.setText("0");
53 | }
54 | mEditTexts[i] = editText;
55 | mGridLayout.addView(editText, mGridLayout.getWidth() / 5, mGridLayout.getHeight() / 4);
56 | }
57 | }
58 | });
59 |
60 | mBtnOk.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | ColorMatrix colorMatrix = new ColorMatrix();
64 | colorMatrix.set(getColorMatrix());
65 | mImageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
66 | }
67 | });
68 |
69 | mBtnReset.setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View v) {
72 | ColorMatrix colorMatrix = new ColorMatrix();
73 | colorMatrix.set(getInitColorMatrix());
74 | mImageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
75 | }
76 | });
77 |
78 | mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.test);
79 | mImageView.setImageBitmap(mBitmap);
80 |
81 | }
82 |
83 | private float[] getColorMatrix() {
84 | for (int i = 0; i < 20; i++) {
85 | mColorMatrix[i] = Float.parseFloat(mEditTexts[i].getText().toString());
86 | }
87 | return mColorMatrix;
88 | }
89 |
90 | private float[] getInitColorMatrix() {
91 | for (int i = 0; i < 20; i++) {
92 | if (i % 6 == 0) {
93 | mColorMatrix[i] = 1;
94 | mEditTexts[i].setText("1");
95 | } else {
96 | mColorMatrix[i] = 0;
97 | mEditTexts[i].setText("0");
98 | }
99 | }
100 | return mColorMatrix;
101 | }
102 |
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lcw/beauty/demo1/BeautyActivityFour.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo1;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.Canvas;
6 | import android.graphics.ColorMatrix;
7 | import android.graphics.ColorMatrixColorFilter;
8 | import android.graphics.Rect;
9 | import android.os.Bundle;
10 | import android.support.annotation.NonNull;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.support.v7.widget.GridLayoutManager;
13 | import android.support.v7.widget.RecyclerView;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.ImageView;
18 |
19 | import com.lcw.beauty.R;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * 简单滤镜效果演示
26 | */
27 | public class BeautyActivityFour extends AppCompatActivity {
28 |
29 | private RecyclerView mRecyclerView;
30 | private BeautyAdapter mBeautyAdapter;
31 | private List mColorMatrixList;
32 |
33 | private Bitmap mBitmap;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_beauty_four);
39 |
40 | mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.test);
41 |
42 | mColorMatrixList = new ArrayList();
43 | mColorMatrixList.add(BeautyUtil.colormatrix_huguang);
44 | mColorMatrixList.add(BeautyUtil.colormatrix_hepian);
45 | mColorMatrixList.add(BeautyUtil.colormatrix_landiao);
46 | mColorMatrixList.add(BeautyUtil.colormatrix_qingning);
47 | mColorMatrixList.add(BeautyUtil.colormatrix_yese);
48 | mColorMatrixList.add(BeautyUtil.colormatrix_fugu);
49 | mColorMatrixList.add(BeautyUtil.colormatrix_huan_huang);
50 | mColorMatrixList.add(BeautyUtil.colormatrix_jiuhong);
51 | mColorMatrixList.add(BeautyUtil.colormatrix_chuan_tong);
52 | mColorMatrixList.add(BeautyUtil.colormatrix_ruise);
53 | mColorMatrixList.add(BeautyUtil.colormatrix_gete);
54 | mColorMatrixList.add(BeautyUtil.colormatrix_menghuan);
55 | mColorMatrixList.add(BeautyUtil.colormatrix_langman);
56 | mColorMatrixList.add(BeautyUtil.colormatrix_danya);
57 | mColorMatrixList.add(BeautyUtil.colormatrix_jiao_pian);
58 | mColorMatrixList.add(BeautyUtil.colormatrix_guangyun);
59 | mColorMatrixList.add(BeautyUtil.colormatrix_heibai);
60 | mColorMatrixList.add(BeautyUtil.colormatrix_huaijiu);
61 | mColorMatrixList.add(BeautyUtil.colormatrix_fanse);
62 |
63 | mRecyclerView = findViewById(R.id.recyclerView);
64 | mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
65 | mRecyclerView.addItemDecoration(new ItemDecoration());
66 | mBeautyAdapter = new BeautyAdapter();
67 | mRecyclerView.setAdapter(mBeautyAdapter);
68 |
69 | }
70 |
71 |
72 | /**
73 | * 滤镜列表Adapter
74 | */
75 | class BeautyAdapter extends RecyclerView.Adapter {
76 |
77 | @NonNull
78 | @Override
79 | public BeautyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
80 | View view = LayoutInflater.from(BeautyActivityFour.this).inflate(R.layout.item_recyclerview_image, null, false);
81 | BeautyViewHolder beautyViewHolder = new BeautyViewHolder(view);
82 | return beautyViewHolder;
83 | }
84 |
85 | @Override
86 | public void onBindViewHolder(@NonNull BeautyViewHolder holder, int position) {
87 | ImageView imageView = holder.imageView;
88 | if (imageView != null) {
89 | imageView.setImageBitmap(mBitmap);
90 | ColorMatrix colorMatrix = new ColorMatrix();
91 | colorMatrix.set(mColorMatrixList.get(position));
92 | imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
93 | }
94 | }
95 |
96 | @Override
97 | public int getItemCount() {
98 | return mColorMatrixList == null ? 0 : mColorMatrixList.size();
99 | }
100 |
101 | class BeautyViewHolder extends RecyclerView.ViewHolder {
102 |
103 | private ImageView imageView;
104 |
105 | public BeautyViewHolder(View itemView) {
106 | super(itemView);
107 | imageView = itemView.findViewById(R.id.imageView);
108 | }
109 | }
110 | }
111 |
112 | /**
113 | * 滤镜列表边框
114 | */
115 | class ItemDecoration extends RecyclerView.ItemDecoration {
116 | @Override
117 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
118 | super.onDraw(c, parent, state);
119 | }
120 |
121 | @Override
122 | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
123 | super.onDrawOver(c, parent, state);
124 | }
125 |
126 | @Override
127 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
128 | outRect.set(3, 3, 3, 3);
129 | }
130 | }
131 |
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/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/lcw/beauty/demo1/BeautyUtil.java:
--------------------------------------------------------------------------------
1 | package com.lcw.beauty.demo1;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.ColorMatrix;
7 | import android.graphics.ColorMatrixColorFilter;
8 | import android.graphics.Paint;
9 | import android.util.Log;
10 |
11 | /**
12 | * Create by: chenWei.li
13 | * Date: 2018/11/8
14 | * Time: 下午11:02
15 | * Email: lichenwei.me@foxmail.com
16 | */
17 | public class BeautyUtil {
18 |
19 |
20 | /**
21 | * 调整图片的色相,饱和度,灰度
22 | *
23 | * @param srcBitmap
24 | * @param rotate
25 | * @param saturation
26 | * @param scale
27 | * @return
28 | */
29 | public static Bitmap beautyImage(Bitmap srcBitmap, float rotate, float saturation, float scale) {
30 |
31 | //调整色相
32 | ColorMatrix rotateMatrix = new ColorMatrix();
33 | rotateMatrix.setRotate(0, rotate);
34 | rotateMatrix.setRotate(1, rotate);
35 | rotateMatrix.setRotate(2, rotate);
36 |
37 | //调整色彩饱和度
38 | ColorMatrix saturationMatrix = new ColorMatrix();
39 | saturationMatrix.setSaturation(saturation);
40 |
41 | //调整灰度
42 | ColorMatrix scaleMatrix = new ColorMatrix();
43 | scaleMatrix.setScale(scale, scale, scale, 1);
44 |
45 | //叠加效果
46 | ColorMatrix colorMatrix = new ColorMatrix();
47 | colorMatrix.postConcat(rotateMatrix);
48 | colorMatrix.postConcat(saturationMatrix);
49 | colorMatrix.postConcat(scaleMatrix);
50 |
51 | //创建一个大小相同的空白Bitmap
52 | Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888);
53 | //载入Canvas,Paint
54 | Canvas canvas = new Canvas(dstBitmap);
55 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
56 | paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
57 | //绘图
58 | canvas.drawBitmap(srcBitmap, 0, 0, paint);
59 |
60 | return dstBitmap;
61 | }
62 |
63 |
64 | /**
65 | * 通过更改图片像素点的RGBA值,生成底片效果
66 | *
67 | * @param scrBitmap
68 | * @return
69 | */
70 | public static Bitmap beautyImage(Bitmap scrBitmap) {
71 |
72 | int width = scrBitmap.getWidth();
73 | int height = scrBitmap.getHeight();
74 | int count = width * height;
75 |
76 | int[] oldPixels = new int[count];
77 | int[] newPixels = new int[count];
78 |
79 | scrBitmap.getPixels(oldPixels, 0, width, 0, 0, width, height);
80 |
81 | for (int i = 0; i < oldPixels.length; i++) {
82 | int pixel = oldPixels[i];
83 | int r = Color.red(pixel);
84 | int g = Color.green(pixel);
85 | int b = Color.blue(pixel);
86 |
87 | r = 255 - r;
88 | g = 255 - g;
89 | b = 255 - b;
90 |
91 | if (r > 255) {
92 | r = 255;
93 | }
94 | if (g > 255) {
95 | g = 255;
96 | }
97 | if (b > 255) {
98 | b = 255;
99 | }
100 |
101 | if (r < 0) {
102 | r = 0;
103 | }
104 | if (g < 0) {
105 | g = 0;
106 | }
107 | if (b < 0) {
108 | b = 0;
109 | }
110 |
111 | newPixels[i] = Color.rgb(r, g, b);
112 |
113 | }
114 |
115 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
116 | bitmap.setPixels(newPixels, 0, width, 0, 0, width, height);
117 |
118 | return bitmap;
119 | }
120 |
121 |
122 | // 黑白
123 | public static final float colormatrix_heibai[] = {0.8f, 1.6f, 0.2f, 0,
124 | -163.9f, 0.8f, 1.6f, 0.2f, 0, -163.9f, 0.8f, 1.6f, 0.2f, 0,
125 | -163.9f, 0, 0, 0, 1.0f, 0};
126 | // 怀旧
127 | public static final float colormatrix_huaijiu[] = {0.2f, 0.5f, 0.1f, 0,
128 | 40.8f, 0.2f, 0.5f, 0.1f, 0, 40.8f, 0.2f, 0.5f, 0.1f, 0, 40.8f, 0,
129 | 0, 0, 1, 0};
130 | // 哥特
131 | public static final float colormatrix_gete[] = {1.9f, -0.3f, -0.2f, 0,
132 | -87.0f, -0.2f, 1.7f, -0.1f, 0, -87.0f, -0.1f, -0.6f, 2.0f, 0,
133 | -87.0f, 0, 0, 0, 1.0f, 0};
134 | // 淡雅
135 | public static final float colormatrix_danya[] = {0.6f, 0.3f, 0.1f, 0,
136 | 73.3f, 0.2f, 0.7f, 0.1f, 0, 73.3f, 0.2f, 0.3f, 0.4f, 0, 73.3f, 0,
137 | 0, 0, 1.0f, 0};
138 | // 蓝调
139 | public static final float colormatrix_landiao[] = {2.1f, -1.4f, 0.6f,
140 | 0.0f, -71.0f, -0.3f, 2.0f, -0.3f, 0.0f, -71.0f, -1.1f, -0.2f, 2.6f,
141 | 0.0f, -71.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f};
142 | // 光晕
143 | public static final float colormatrix_guangyun[] = {0.9f, 0, 0, 0, 64.9f,
144 | 0, 0.9f, 0, 0, 64.9f, 0, 0, 0.9f, 0, 64.9f, 0, 0, 0, 1.0f, 0};
145 |
146 | // 梦幻
147 | public static final float colormatrix_menghuan[] = {0.8f, 0.3f, 0.1f,
148 | 0.0f, 46.5f, 0.1f, 0.9f, 0.0f, 0.0f, 46.5f, 0.1f, 0.3f, 0.7f, 0.0f,
149 | 46.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f};
150 | // 酒红
151 | public static final float colormatrix_jiuhong[] = {1.2f, 0.0f, 0.0f, 0.0f,
152 | 0.0f, 0.0f, 0.9f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.8f, 0.0f, 0.0f,
153 | 0, 0, 0, 1.0f, 0};
154 | // 胶片
155 | public static final float colormatrix_fanse[] = {-1.0f, 0.0f, 0.0f, 0.0f,
156 | 255.0f, 0.0f, -1.0f, 0.0f, 0.0f, 255.0f, 0.0f, 0.0f, -1.0f, 0.0f,
157 | 255.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f};
158 | // 湖光掠影
159 | public static final float colormatrix_huguang[] = {0.8f, 0.0f, 0.0f, 0.0f,
160 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.9f, 0.0f, 0.0f,
161 | 0, 0, 0, 1.0f, 0};
162 | // 褐片
163 | public static final float colormatrix_hepian[] = {1.0f, 0.0f, 0.0f, 0.0f,
164 | 0.0f, 0.0f, 0.8f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.8f, 0.0f, 0.0f,
165 | 0, 0, 0, 1.0f, 0};
166 | // 复古
167 | public static final float colormatrix_fugu[] = {0.9f, 0.0f, 0.0f, 0.0f,
168 | 0.0f, 0.0f, 0.8f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f,
169 | 0, 0, 0, 1.0f, 0};
170 | // 泛黄
171 | public static final float colormatrix_huan_huang[] = {1.0f, 0.0f, 0.0f,
172 | 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f,
173 | 0.0f, 0, 0, 0, 1.0f, 0};
174 | // 传统
175 | public static final float colormatrix_chuan_tong[] = {1.0f, 0.0f, 0.0f, 0,
176 | -10f, 0.0f, 1.0f, 0.0f, 0, -10f, 0.0f, 0.0f, 1.0f, 0, -10f, 0, 0,
177 | 0, 1, 0};
178 | // 胶片2
179 | public static final float colormatrix_jiao_pian[] = {0.71f, 0.2f, 0.0f,
180 | 0.0f, 60.0f, 0.0f, 0.94f, 0.0f, 0.0f, 60.0f, 0.0f, 0.0f, 0.62f,
181 | 0.0f, 60.0f, 0, 0, 0, 1.0f, 0};
182 |
183 | // 锐色
184 | public static final float colormatrix_ruise[] = {4.8f, -1.0f, -0.1f, 0,
185 | -388.4f, -0.5f, 4.4f, -0.1f, 0, -388.4f, -0.5f, -1.0f, 5.2f, 0,
186 | -388.4f, 0, 0, 0, 1.0f, 0};
187 | // 清宁
188 | public static final float colormatrix_qingning[] = {0.9f, 0, 0, 0, 0, 0,
189 | 1.1f, 0, 0, 0, 0, 0, 0.9f, 0, 0, 0, 0, 0, 1.0f, 0};
190 | // 浪漫
191 | public static final float colormatrix_langman[] = {0.9f, 0, 0, 0, 63.0f,
192 | 0, 0.9f, 0, 0, 63.0f, 0, 0, 0.9f, 0, 63.0f, 0, 0, 0, 1.0f, 0};
193 | // 夜色
194 | public static final float colormatrix_yese[] = {1.0f, 0.0f, 0.0f, 0.0f,
195 | -66.6f, 0.0f, 1.1f, 0.0f, 0.0f, -66.6f, 0.0f, 0.0f, 1.0f, 0.0f,
196 | -66.6f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f};
197 |
198 | }
199 |
--------------------------------------------------------------------------------