use of android.graphics.ColorMatrix in project AndroidUtilCode by Blankj.
the class ImageUtils method toGray.
/**
* 转为灰度图片
*
* @param src 源图片
* @param recycle 是否回收
* @return 灰度图
*/
public static Bitmap toGray(Bitmap src, boolean recycle) {
if (isEmptyBitmap(src))
return null;
Bitmap grayBitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(grayBitmap);
Paint paint = new Paint();
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(colorMatrix);
paint.setColorFilter(colorMatrixColorFilter);
canvas.drawBitmap(src, 0, 0, paint);
if (recycle && !src.isRecycled())
src.recycle();
return grayBitmap;
}
use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.
the class ImageHelper method toGrayscale.
private static Bitmap toGrayscale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
paint.setAntiAlias(true);
ColorMatrix cm = new ColorMatrix();
final Rect rect = new Rect(0, 0, width, height);
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, rect, rect, paint);
return bmpGrayscale;
}
use of android.graphics.ColorMatrix in project android_frameworks_base by ResurrectionRemix.
the class LockscreenShortcutsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lockscreen_shortcuts);
getActionBar().setDisplayHomeAsUpEnabled(true);
mPicker = new ShortcutPickHelper(this, this);
mShortcutHelper = new LockscreenShortcutsHelper(this, this);
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
mFilter = new ColorMatrixColorFilter(cm);
ImageView unlockButton = (ImageView) findViewById(R.id.middle_button);
mDefaultTintList = unlockButton.getImageTintList();
createActionList();
initiateViews();
updateDrawables();
}
use of android.graphics.ColorMatrix in project android_frameworks_base by crdroidandroid.
the class ColorHelper method toGrayscale.
private static Bitmap toGrayscale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
use of android.graphics.ColorMatrix in project smartmodule by carozhu.
the class Bitmaputil method toGrayscale.
/**
* 图片去色,返回灰度图片
*
* @param bmpOriginal 传入的图片
* @return 去色后的图片
*/
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Config.RGB_565);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
Aggregations