use of android.graphics.ColorMatrix in project android_packages_apps_Launcher2 by CyanogenMod.
the class AppsCustomizePagedView method getShortcutPreview.
private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) {
Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
final Canvas c = mCachedShortcutPreviewCanvas.get();
if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) {
tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
mCachedShortcutPreviewBitmap.set(tempBitmap);
} else {
c.setBitmap(tempBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
c.setBitmap(null);
}
// Render the icon
Drawable icon = mIconCache.getFullResIcon(info);
int paddingTop = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
int paddingLeft = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
int paddingRight = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
c.setBitmap(preview);
Paint p = mCachedShortcutPreviewPaint.get();
if (p == null) {
p = new Paint();
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
p.setAlpha((int) (255 * 0.06f));
//float density = 1f;
//p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL));
mCachedShortcutPreviewPaint.set(p);
}
c.drawBitmap(tempBitmap, 0, 0, p);
c.setBitmap(null);
renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
return preview;
}
use of android.graphics.ColorMatrix in project Fairphone by Kwamecorp.
the class AppsCustomizePagedView method getShortcutPreview.
private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) {
Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
final Canvas c = mCachedShortcutPreviewCanvas.get();
if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) {
tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
mCachedShortcutPreviewBitmap.set(tempBitmap);
} else {
c.setBitmap(tempBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
c.setBitmap(null);
}
// Render the icon
Drawable icon = mIconCache.getFullResIcon(info);
int paddingTop = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
int paddingLeft = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
int paddingRight = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
c.setBitmap(preview);
Paint p = mCachedShortcutPreviewPaint.get();
if (p == null) {
p = new Paint();
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
p.setAlpha((int) (255 * 0.06f));
//float density = 1f;
//p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL));
mCachedShortcutPreviewPaint.set(p);
}
c.drawBitmap(tempBitmap, 0, 0, p);
c.setBitmap(null);
renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
return preview;
}
use of android.graphics.ColorMatrix in project glide-transformations by wasabeef.
the class GrayscaleTransformation method transform.
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
Bitmap bitmap = mBitmapPool.get(width, height, config);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, config);
}
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.setSaturation(0f);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(saturation));
canvas.drawBitmap(source, 0, 0, paint);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
use of android.graphics.ColorMatrix in project ThinkAndroid by white-cat.
the class ImageUtils 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, Bitmap.Config.RGB_565);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
paint.setColorFilter(null);
c.drawBitmap(bmpGrayscale, 0, 0, paint);
ColorMatrix cm = new ColorMatrix();
getValueBlackAndWhite();
cm.set(carray);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
use of android.graphics.ColorMatrix in project UltimateAndroid by cymcsg.
the class FoldingLayoutActivity method onCreate.
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.folding_drawer_activity_fold);
mImageView = (ImageView) findViewById(R.id.image_view);
mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING);
mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
mImageView.setImageDrawable(getResources().getDrawable(R.drawable.test));
if (IS_ISC) {
//mTextureView = new TextureView(this);
//mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
}
mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar);
mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view);
mFoldLayout.setFoldListener(mOnFoldListener);
mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);
mItemSelectedListener = new ItemSelectedListener();
mDefaultPaint = new Paint();
mSepiaPaint = new Paint();
ColorMatrix m1 = new ColorMatrix();
ColorMatrix m2 = new ColorMatrix();
m1.setSaturation(0);
m2.setScale(1f, .95f, .82f, 1.0f);
m1.setConcat(m2, m1);
mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
mFoldLayout.setNumberOfFolds(mNumberOfFolds);
}
Aggregations