-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
meng.wu1
committed
Dec 1, 2022
1 parent
b85d98f
commit 96237a4
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
lib_util/src/main/java/com/mirkowu/lib_util/ColorFilterUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.mirkowu.lib_util; | ||
|
||
import android.app.Activity; | ||
import android.graphics.ColorMatrix; | ||
import android.graphics.ColorMatrixColorFilter; | ||
import android.graphics.Paint; | ||
import android.view.View; | ||
|
||
public class ColorFilterUtils { | ||
|
||
/** | ||
* 灰色滤镜效果(eg.悼念日) | ||
* | ||
* @param view | ||
*/ | ||
public static void setGrayFilter(View view) { | ||
Paint paint = new Paint(); | ||
ColorMatrix cm = new ColorMatrix(); | ||
cm.setSaturation(0);//???? | ||
paint.setColorFilter(new ColorMatrixColorFilter(cm)); | ||
view.setLayerType(View.LAYER_TYPE_HARDWARE, paint); | ||
} | ||
|
||
/** | ||
* 移除滤镜 | ||
* | ||
* @param view | ||
*/ | ||
public static void removeFilter(View view) { | ||
Paint paint = new Paint(); | ||
// ColorMatrix cm = new ColorMatrix(); | ||
// cm.setSaturation(0);//???? | ||
// paint.setColorFilter(new ColorMatrixColorFilter(cm)); | ||
view.setLayerType(View.LAYER_TYPE_HARDWARE, paint); | ||
} | ||
|
||
public static void setGrayFilter(Activity activity) { | ||
setGrayFilter(activity.getWindow().getDecorView()); | ||
} | ||
|
||
public static void removeFilter(Activity activity) { | ||
removeFilter(activity.getWindow().getDecorView()); | ||
} | ||
|
||
|
||
} |