private void setupBitmap(ImageView imageView, float width, float height) {
Drawable drawable = imageView.getDrawable();
if (drawable == null) {
return;
}
try {
bitmap = (drawable instanceof BitmapDrawable) ?
((BitmapDrawable) drawable).getBitmap() :
Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
} catch (Exception e) {
e.printStackTrace();
}
if (bitmap == null) {
imageView.invalidate();
return;
}
paint = new Paint(ANTI_ALIAS_FLAG);
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(bitmapShader);
if (imageView.getScaleType() != ImageView.ScaleType.CENTER_CROP && imageView.getScaleType() != ImageView.ScaleType.FIT_XY) {
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
bitmapShader.setLocalMatrix(setUpScaleType(bitmap, imageView, width, height));
imageView.invalidate();
}
java类android.graphics.Shader的实例源码
ObliqueView.java 文件源码
项目:Oblique
阅读 31
收藏 0
点赞 0
评论 0
ShimmerViewHelper.java 文件源码
项目:VirtualHook
阅读 33
收藏 0
点赞 0
评论 0
private void resetLinearGradient() {
// our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center
// when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP)
// initially, the linear gradient is positioned on the left side of the view
linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0,
new int[]{
primaryColor,
reflectionColor,
primaryColor,
},
new float[]{
0,
0.5f,
1
},
Shader.TileMode.CLAMP
);
paint.setShader(linearGradient);
}
ColorWheelView.java 文件源码
项目:SimpleDialogFragments
阅读 38
收藏 0
点赞 0
评论 0
protected void updateColorDependant(boolean hsvChanged, boolean hueChanged){
if (hueChanged) {
Shader base = new LinearGradient(A.x, A.y, (B.x + C.x) / 2, (B.y + C.y) / 2,
Color.HSVToColor(new float[]{mColor.hue(), 1, 1}), Color.BLACK, Shader.TileMode.CLAMP);
Shader light = new LinearGradient((A.x + C.x) / 2, (A.y + C.y) / 2, B.x, B.y,
Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP);
Shader both = new ComposeShader(base, light, PorterDuff.Mode.ADD);
paint.setShader(both);
}
if (hsvChanged) {
dotPaint.setColor(mColor.inverted().rgb());
dot = new PointF(
C.x + (B.x - C.x + (A.x - B.x) * mColor.sat()) * mColor.val(),
C.y + (B.y - C.y + (A.y - B.y) * mColor.sat()) * mColor.val());
}
}
SaturationValueDrawable.java 文件源码
项目:spline
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void draw(Canvas canvas) {
Rect b = getBounds();
int height = b.height();
int width = b.width();
Paint valuePaint = new Paint();
valuePaint.setShader(
new LinearGradient(0, mInset, 0, height - mInset,
Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP)
);
float hsv[] = {mHue, 1.0f, 1.0f};
int pureHue = Color.HSVToColor(hsv);
Paint saturationPaint = new Paint();
saturationPaint.setShader(
new LinearGradient(mInset, 0, width - mInset, 0,
Color.WHITE, pureHue, Shader.TileMode.CLAMP)
);
saturationPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
canvas.drawRect(b, valuePaint);
canvas.drawRect(b, saturationPaint);
}
BubbleDrawable.java 文件源码
项目:BubbleView
阅读 33
收藏 0
点赞 0
评论 0
public BubbleDrawable(Builder builder) {
triangleWidth = builder.triangleWidth;
triangleHeight = builder.triangleHeight;
offset = builder.offset;
radius = builder.radius;
orientation = builder.orientation;
bitmap = builder.bitmap;
borderWidth = builder.borderWidth;
centerArrow = builder.centerArrow;
shadowRadius = builder.shadowRadius;
shadowColor = builder.shadowColor;
borderPaint.setStyle(Paint.Style.STROKE);
borderPaint.setStrokeCap(Paint.Cap.ROUND);
borderPaint.setColor(builder.borderColor);
leftTopRadiusRect = new RectF();
rightBottomRadiusRect = new RectF();
leftBottomRadiusRect = new RectF();
rightTopRadiusRect = new RectF();
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
bitmapPaint.setShader(bitmapShader);
}
SVBar.java 文件源码
项目:xlight_android_native
阅读 32
收藏 0
点赞 0
评论 0
/**
* Set the bar color. <br>
* <br>
* Its discouraged to use this method.
*
* @param color
*/
public void setColor(int color) {
int x1, y1;
if(mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
y1 = mBarThickness;
} else {
x1 = mBarThickness;
y1 = (mBarLength + mBarPointerHaloRadius);
}
Color.colorToHSV(color, mHSVColor);
shader = new LinearGradient(mBarPointerHaloRadius, 0,
x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
Shader.TileMode.CLAMP);
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
if(mPicker.hasOpacityBar())
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
RoundedCornersTransformation.java 文件源码
项目:Picasso-transformations
阅读 31
收藏 0
点赞 0
评论 0
@Override public Bitmap transform(Bitmap source) {
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
source.recycle();
return bitmap;
}
CircleImageView.java 文件源码
项目:OpenEyesReading-android
阅读 34
收藏 0
点赞 0
评论 0
private void setupView() {
if (!mReady) {
mSetupPending = true;
return;
}
if (mBitmap == null) return;
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setAntiAlias(true);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
mBorderRect.set(0, 0, getWidth(), getHeight());
mDrawableRect.set(mBorderRect);
mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
updateShaderMatrix();
invalidate();
}
FriskyShimmerViewHelper.java 文件源码
项目:FriskyImage
阅读 33
收藏 0
点赞 0
评论 0
private void resetLinearGradient() {
// our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center
// when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP)
// initially, the linear gradient is positioned on the left side of the view
linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0,
new int[]{
primaryColor,
reflectionColor,
primaryColor,
},
new float[]{
0,
0.5f,
1
},
Shader.TileMode.CLAMP
);
paint.setShader(linearGradient);
}
ShimmerLayout.java 文件源码
项目:ShimmerLayout
阅读 31
收藏 0
点赞 0
评论 0
private Bitmap getSourceMaskBitmap() {
if (sourceMaskBitmap != null) {
return sourceMaskBitmap;
}
int width = maskRect.width();
int height = getHeight();
final int edgeColor = reduceColorAlphaValueToZero(shimmerColor);
LinearGradient gradient = new LinearGradient(
-maskRect.left, 0,
width + maskRect.left, 0,
new int[]{edgeColor, shimmerColor, shimmerColor, edgeColor},
getGradientColorDistribution(),
Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(gradient);
sourceMaskBitmap = createBitmap(width, height);
Canvas canvas = new Canvas(sourceMaskBitmap);
canvas.rotate(shimmerAngle, width / 2, height / 2);
canvas.drawRect(-maskRect.left, maskRect.top, width + maskRect.left, maskRect.bottom, paint);
return sourceMaskBitmap;
}
SVBar.java 文件源码
项目:microMathematics
阅读 31
收藏 0
点赞 0
评论 0
/**
* Set the bar color. <br>
* <br>
* Its discouraged to use this method.
*
* @param color
*/
public void setColor(int color) {
int x1, y1;
if (mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
y1 = mBarThickness;
} else {
x1 = mBarThickness;
y1 = (mBarLength + mBarPointerHaloRadius);
}
Color.colorToHSV(color, mHSVColor);
shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1,
new int[] { Color.WHITE, color, Color.BLACK }, null,
Shader.TileMode.CLAMP);
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
if (mPicker.hasOpacityBar())
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Pessoa.java 文件源码
项目:app_secompufscar
阅读 36
收藏 0
点赞 0
评论 0
public Bitmap getFotoBitmap(Context context) {
Bitmap image;
if (this.foto != null) {
image = BitmapFactory.decodeByteArray(this.foto, 0, this.foto.length);
} else {
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.pessoa_foto_default);
}
Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
Canvas canvas = new Canvas(imageRounded);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100
return imageRounded;
}
HoldingDrawable.java 文件源码
项目:HoldingButton
阅读 40
收藏 0
点赞 0
评论 0
public void setCancelIcon(Bitmap bitmap) {
if (bitmap != null) {
mCancelIconWidth = bitmap.getWidth();
mCancelIconHeight = bitmap.getHeight();
mCancelIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mCancelIconShader.setLocalMatrix(mCancelIconMatrix);
mCancelIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCancelIconPaint.setShader(mCancelIconShader);
mCancelIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
invalidateSelf();
} else {
mCancelIconWidth = 0;
mCancelIconHeight = 0;
mCancelIconMatrix = null;
mCancelIconPaint = null;
}
}
ShimmerViewHelper.java 文件源码
项目:RLibrary
阅读 30
收藏 0
点赞 0
评论 0
private void resetLinearGradient() {
// our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center
// when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP)
// initially, the linear gradient is positioned on the left side of the view
linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0,
new int[]{
primaryColor,
reflectionColor,
primaryColor,
},
new float[]{
0,
0.5f,
1
},
Shader.TileMode.CLAMP
);
paint.setShader(linearGradient);
}
Instagram.java 文件源码
项目:app_secompufscar
阅读 37
收藏 0
点赞 0
评论 0
public static Bitmap getImageRound(byte[] imageByte) {
Bitmap image;
image = BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length);
//TODO: Verificar se o formato da imagem está correto;
Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
Canvas canvas = new Canvas(imageRounded);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100
return imageRounded;
}
CircleImageView.java 文件源码
项目:DMAudioStreamer
阅读 34
收藏 0
点赞 0
评论 0
private void updateShader() {
if (image == null)
return;
// Crop Center Image
image = cropBitmap(image);
// Create Shader
BitmapShader shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
// Center Image in Shader
Matrix matrix = new Matrix();
matrix.setScale((float) canvasSize / (float) image.getWidth(), (float) canvasSize / (float) image.getHeight());
shader.setLocalMatrix(matrix);
// Set Shader in Paint
paint.setShader(shader);
}
TouchImageView.java 文件源码
项目:spinify_android
阅读 35
收藏 0
点赞 0
评论 0
@Override
protected void onDraw(Canvas canvas) {
onDrawReady = true;
imageRenderedAtLeastOnce = true;
if (delayedZoomVariables != null) {
setZoom(delayedZoomVariables.scale, delayedZoomVariables.focusX, delayedZoomVariables.focusY, delayedZoomVariables.scaleType);
delayedZoomVariables = null;
}
super.onDraw(canvas);
if (!zooming) {
buildDrawingCache();
} else {
bitmap = getDrawingCache();
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint = new Paint();
paint.setShader(shader);
eMatrix.reset();
eMatrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
paint.getShader().setLocalMatrix(eMatrix);
canvas.drawCircle(zoomPos.x, zoomPos.y, sizeOfMagnifier, paint);
}
}
RoundedDrawable.java 文件源码
项目:android-project-gallery
阅读 40
收藏 0
点赞 0
评论 0
public RoundedDrawable(Bitmap bitmap)
{
mBitmapWidth = bitmap.getWidth();
mBitmapHeight = bitmap.getHeight();
mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);
mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mBitmapShader.setLocalMatrix(mShaderMatrix);
mBitmapPaint = new Paint();
mBitmapPaint.setStyle(Paint.Style.FILL);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mBorderPaint = new Paint();
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setAntiAlias(true);
mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
mBorderPaint.setStrokeWidth(mBorderWidth);
}
RoundTransformation.java 文件源码
项目:SnakeViewMaker
阅读 25
收藏 0
点赞 0
评论 0
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
if (null == toTransform)
return null;
// outWidth is the width of the target ImageView,and the same to outHeight
// all the ori bitmaps loaded may have different size, in order to the clipped
// the bitmaps have the same size and shape,we use the target ImageView's size
// to create bitmaps
updateDrawBound(toTransform.getWidth(), toTransform.getHeight(), outWidth, outHeight);
Bitmap bitmap = pool.get(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
}
bitmap.setHasAlpha(true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint);
return bitmap;
}
CircleImageView.java 文件源码
项目:HeroVideo-master
阅读 28
收藏 0
点赞 0
评论 0
private void setup()
{
if (!mReady)
{
mSetupPending = true;
return;
}
if (mBitmap == null)
{
return;
}
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPaint.setAntiAlias(true);
mBorderPaint.setColor(mBorderColor);
mBorderPaint.setStrokeWidth(mBorderWidth);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
mBorderRect.set(0, 0, getWidth(), getHeight());
mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);
mDrawableRect.set(mBorderRect);
if (!mBorderOverlay)
{
mDrawableRect.inset(mBorderWidth, mBorderWidth);
}
mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
updateShaderMatrix();
invalidate();
}
OwnCustomView.java 文件源码
项目:Building-Android-UIs-with-Custom-Views
阅读 29
收藏 0
点赞 0
评论 0
@Override
protected void onDraw(Canvas canvas) {
if (firstDraw) {
LinearGradient lg = new LinearGradient(0, 0, getWidth(), getHeight(),
colorArray, null, Shader.TileMode.CLAMP);
backgroundPaint.setShader(lg);
firstDraw = false;
}
canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundPaint);
super.onDraw(canvas);
}
NoiseEffect.java 文件源码
项目:Mire
阅读 28
收藏 0
点赞 0
评论 0
public NoiseEffect(Bitmap bitmap, int grainFPS, float scale) {
super(bitmap, 0, 0);
shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
matrix = new Matrix();
shader.setLocalMatrix(matrix);
paint.setShader(shader);
paint.setAlpha(144);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
lastGrainOffset = System.currentTimeMillis();
this.grainFPS = grainFPS;
this.scale=scale;
}
CircularBorderDrawable.java 文件源码
项目:cwac-crossport
阅读 25
收藏 0
点赞 0
评论 0
/**
* Creates a vertical {@link LinearGradient}
* @return
*/
private Shader createGradientShader() {
final Rect rect = mRect;
copyBounds(rect);
final float borderRatio = mBorderWidth / rect.height();
final int[] colors = new int[6];
colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor);
colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor);
colors[2] = ColorUtils.compositeColors(
ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mCurrentBorderTintColor);
colors[3] = ColorUtils.compositeColors(
ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mCurrentBorderTintColor);
colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor);
colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor);
final float[] positions = new float[6];
positions[0] = 0f;
positions[1] = borderRatio;
positions[2] = 0.5f;
positions[3] = 0.5f;
positions[4] = 1f - borderRatio;
positions[5] = 1f;
return new LinearGradient(
0, rect.top,
0, rect.bottom,
colors, positions,
Shader.TileMode.CLAMP);
}
CircleProgressBar.java 文件源码
项目:GitHub
阅读 33
收藏 0
点赞 0
评论 0
public OvalShadow(int shadowRadius, int circleDiameter) {
super();
mShadowPaint = new Paint();
mShadowRadius = shadowRadius;
mCircleDiameter = circleDiameter;
mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
mShadowRadius, new int[]{
FILL_SHADOW_COLOR, Color.TRANSPARENT
}, null, Shader.TileMode.CLAMP);
mShadowPaint.setShader(mRadialGradient);
}
ImageUtils.java 文件源码
项目:LJFramework
阅读 41
收藏 0
点赞 0
评论 0
/**
* 添加倒影
*
* @param src 源图片的
* @param reflectionHeight 倒影高度
* @param recycle 是否回收
* @return 带倒影图片
*/
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
if (isEmptyBitmap(src)) {
return null;
}
// 原图与倒影之间的间距
final int REFLECTION_GAP = 0;
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight -
reflectionHeight, srcWidth, reflectionHeight, matrix, false);
Bitmap ret = Bitmap.createBitmap(srcWidth,
srcHeight + reflectionHeight, src.getConfig());
Canvas canvas = new Canvas(ret);
canvas.drawBitmap(src, 0, 0, null);
canvas.drawBitmap(reflectionBitmap, 0,
srcHeight + REFLECTION_GAP, null);
Paint paint = new Paint();
paint.setAntiAlias(true);
LinearGradient shader = new LinearGradient(0, srcHeight, 0,
ret.getHeight() +
REFLECTION_GAP, 0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
canvas.drawRect(0,
srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
if (!reflectionBitmap.isRecycled()) {
reflectionBitmap.recycle();
}
if (recycle && !src.isRecycled()) {
src.recycle();
}
return ret;
}
CircleDrawable.java 文件源码
项目:ShortcutMenu
阅读 38
收藏 0
点赞 0
评论 0
public CircleDrawable(Bitmap bitmap, int margin) {
this.margin = margin;
this.oBitmap = bitmap;
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(bitmapShader);
}
TransformationUtils.java 文件源码
项目:GitHub
阅读 29
收藏 0
点赞 0
评论 0
/**
* Creates a bitmap from a source bitmap and rounds the corners.
*
* @param inBitmap the source bitmap to use as a basis for the created bitmap.
* @param width the width of the generated bitmap.
* @param height the height of the generated bitmap.
* @param roundingRadius the corner radius to be applied (in device-specific pixels).
* @return a {@link Bitmap} similar to inBitmap but with rounded corners.
* @throws IllegalArgumentException if roundingRadius, width or height is 0 or less.
*/
public static Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
int width, int height, int roundingRadius) {
Preconditions.checkArgument(width > 0, "width must be greater than 0.");
Preconditions.checkArgument(height > 0, "height must be greater than 0.");
Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0.");
// Alpha is required for this transformation.
Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);
Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888);
result.setHasAlpha(true);
BitmapShader shader = new BitmapShader(toTransform, Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
RectF rect = new RectF(0, 0, result.getWidth(), result.getHeight());
BITMAP_DRAWABLE_LOCK.lock();
try {
Canvas canvas = new Canvas(result);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint);
clear(canvas);
} finally {
BITMAP_DRAWABLE_LOCK.unlock();
}
if (!toTransform.equals(inBitmap)) {
pool.put(toTransform);
}
return result;
}
AbsFocusBorder.java 文件源码
项目:ShimmerDemo
阅读 46
收藏 0
点赞 0
评论 0
private void setShimmerAnimating(boolean shimmerAnimating)
{
mShimmerAnimating = shimmerAnimating;
if (mShimmerAnimating)
{
mShimmerLinearGradient = new LinearGradient(0, 0, mFrameRectF.width(), mFrameRectF.height(),
new int[] {0x00FFFFFF, 0x1AFFFFFF, mShimmerColor, 0x1AFFFFFF, 0x00FFFFFF},
new float[] {0f, 0.2f, 0.5f, 0.8f, 1f}, Shader.TileMode.CLAMP);
mShimmerPaint.setShader(mShimmerLinearGradient);
}
}
ForecastView.java 文件源码
项目:GitHub
阅读 97
收藏 0
点赞 0
评论 0
private void initGradient() {
float centerX = getWidth() * 0.5f;
Shader gradient = new LinearGradient(
centerX, 0, centerX, getHeight(),
currentGradient, null,
Shader.TileMode.MIRROR);
gradientPaint.setShader(gradient);
}
RoundedBitmapDrawable.java 文件源码
项目:GitHub
阅读 32
收藏 0
点赞 0
评论 0
private void updatePaint() {
Bitmap bitmap = getBitmap();
if (mLastBitmap == null || mLastBitmap.get() != bitmap) {
mLastBitmap = new WeakReference<Bitmap>(bitmap);
mPaint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
mIsShaderTransformDirty = true;
}
if (mIsShaderTransformDirty) {
mPaint.getShader().setLocalMatrix(mTransform);
mIsShaderTransformDirty = false;
}
}