use of android.graphics.ColorMatrix in project android_frameworks_base by crdroidandroid.
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 smartmodule by carozhu.
the class Bitmaputil method returnContrastBitmap.
/**
* 改变bitmap 对比度
*
* @param bitmap
* @param progress
* @return
*/
public static Bitmap returnContrastBitmap(Bitmap bitmap, int progress) {
//曝光度
Bitmap contrast_bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
// int brightness = progress - 127;
float contrast = (float) ((progress + 64) / 128.0);
ColorMatrix contrast_cMatrix = new ColorMatrix();
contrast_cMatrix.set(new float[] { contrast, 0, 0, 0, 0, 0, // 改变对比度
contrast, // 改变对比度
0, // 改变对比度
0, // 改变对比度
0, 0, 0, contrast, 0, 0, 0, 0, 0, 1, 0 });
Paint contrast_paint = new Paint();
contrast_paint.setColorFilter(new ColorMatrixColorFilter(contrast_cMatrix));
Canvas contrast_canvas = new Canvas(contrast_bmp);
// 在Canvas上绘制一个已经存在的Bitmap。这样,dstBitmap就和srcBitmap一摸一样了
contrast_canvas.drawBitmap(bitmap, 0, 0, contrast_paint);
return contrast_bmp;
}
use of android.graphics.ColorMatrix in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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 9GAG by Mixiaoxiao.
the class SquareProgressBar method setImageGrayscale.
/**
* You can set the image to b/w with this method. Works fine with the
* opacity.
*
* @param greyscale
* true if the grayscale should be activated.
* @since 1.2.0 / but never used in the example application
*/
public void setImageGrayscale(boolean greyscale) {
this.greyscale = greyscale;
if (greyscale) {
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
} else {
imageView.setColorFilter(null);
}
}
Aggregations