下面列出了android.graphics.drawable.Drawable#setFilterBitmap() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint("Range")
public void applyTo(Drawable drawable) {
if (drawable == null) {
return;
}
if (mAlpha != UNSET) {
drawable.setAlpha(mAlpha);
}
if (mIsSetColorFilter) {
drawable.setColorFilter(mColorFilter);
}
if (mDither != UNSET) {
drawable.setDither(mDither != 0);
}
if (mFilterBitmap != UNSET) {
drawable.setFilterBitmap(mFilterBitmap != 0);
}
}
@SuppressLint("Range")
public void applyTo(Drawable drawable) {
if (drawable == null) {
return;
}
if (mAlpha != UNSET) {
drawable.setAlpha(mAlpha);
}
if (mIsSetColorFilter) {
drawable.setColorFilter(mColorFilter);
}
if (mDither != UNSET) {
drawable.setDither(mDither != 0);
}
if (mFilterBitmap != UNSET) {
drawable.setFilterBitmap(mFilterBitmap != 0);
}
}
/**
* Sets various paint properties on the drawable
* @param drawable Drawable on which to set the properties
* @param properties wrapper around property values to set on the drawable
*/
public static void setDrawableProperties(Drawable drawable, DrawableProperties properties) {
if (drawable == null || properties == null) {
return;
}
drawable.setAlpha(properties.getAlpha());
drawable.setColorFilter(properties.getColorFilter());
drawable.setDither(properties.isDither());
drawable.setFilterBitmap(properties.isFilterBitmap());
}
@Override
public void setFilterBitmap(boolean filterBitmap) {
mDrawableProperties.setFilterBitmap(filterBitmap);
for (int i = 0; i < mLayers.length; i++) {
Drawable drawable = mLayers[i];
if (drawable != null) {
drawable.setFilterBitmap(filterBitmap);
}
}
}
private void drawIcon(Canvas canvas, Drawable icon, float l, float t, float r, float b, Paint paint) {
icon.setBounds((int) l, (int) t, (int) r, (int) b);
icon.setFilterBitmap(true);
icon.setAlpha(paint.getAlpha());
icon.draw(canvas);
}
private Bitmap generateShortcutPreview(
Launcher launcher, ResolveInfo info, int maxWidth, int maxHeight, Bitmap preview) {
final Canvas c = new Canvas();
if (preview == null) {
preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
c.setBitmap(preview);
} else if (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight) {
throw new RuntimeException("Improperly sized bitmap passed as argument");
} else {
// Reusing bitmap. Clear it.
c.setBitmap(preview);
c.drawColor(0, PorterDuff.Mode.CLEAR);
}
Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info.activityInfo));
icon.setFilterBitmap(true);
// Draw a desaturated/scaled version of the icon in the background as a watermark
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
icon.setAlpha((int) (255 * 0.06f));
Resources res = mContext.getResources();
int paddingTop = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
int paddingLeft = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
int paddingRight = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
icon.setBounds(paddingLeft, paddingTop,
paddingLeft + scaledIconWidth, paddingTop + scaledIconWidth);
icon.draw(c);
// Draw the final icon at top left corner.
// TODO: use top right for RTL
int appIconSize = launcher.getDeviceProfile().iconSizePx;
icon.setAlpha(255);
icon.setColorFilter(null);
icon.setBounds(0, 0, appIconSize, appIconSize);
icon.draw(c);
c.setBitmap(null);
return preview;
}