use of android.graphics.BitmapShader in project GestureViews by alexvasilkov.
the class CircleGestureImageView method setup.
private void setup() {
Bitmap bitmap = isCircle ? getBitmapFromDrawable(getDrawable()) : null;
if (bitmap != null) {
bitmapPaint.setShader(new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP));
updateShaderMatrix();
} else {
bitmapPaint.setShader(null);
}
invalidate();
}
use of android.graphics.BitmapShader in project SmartAndroidSource by jaychou2012.
the class IcsProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /*
* else if (drawable instanceof StateListDrawable) { StateListDrawable
* in = (StateListDrawable) drawable; StateListDrawable out = new
* StateListDrawable(); int numStates = in.getStateCount(); for (int i =
* 0; i < numStates; i++) { out.addState(in.getStateSet(i),
* tileify(in.getStateDrawable(i), clip)); } return out;
*
* }
*/
if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.BitmapShader in project Klyph by jonathangerbaud.
the class ProfileIcon method draw.
@Override
public void draw(Canvas canvas) {
Matrix matrix = new Matrix();
matrix.setScale(mScale, mScale);
int x = (int) (mBitmap.getWidth() - mSide) / 2;
int y = (int) (mBitmap.getHeight() - mSide) / 2;
Bitmap b = Bitmap.createBitmap(mBitmap, x, y, mSide, mSide, matrix, true);
BitmapShader bitmapShader = new BitmapShader(b, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint.setShader(bitmapShader);
Paint bPaint = new Paint();
bPaint.setAntiAlias(true);
bPaint.setColor(mColor);
canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, bPaint);
RectF r = new RectF();
r.set(2, 2, mRect.right - 2, mRect.bottom - 2);
canvas.drawRoundRect(r, mCornerRadius, mCornerRadius, mPaint);
}
use of android.graphics.BitmapShader in project android-oss by kickstarter.
the class CircleTransformation method transform.
@Override
public Bitmap transform(@NonNull final Bitmap source) {
final int size = Math.min(source.getWidth(), source.getHeight());
this.x = (source.getWidth() - size) / 2;
this.y = (source.getHeight() - size) / 2;
final Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
final Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
final Bitmap bitmap = Bitmap.createBitmap(size, size, config);
final Canvas canvas = new Canvas(bitmap);
final Paint paint = new Paint();
final BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
final float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
use of android.graphics.BitmapShader in project mobile-android by photo.
the class RepeatableHorizontalDrawable method init.
private void init(Bitmap bitmap) {
mBitmap = bitmap;
if (mBitmap != null) {
mShader = new BitmapShader(mBitmap, TileMode.REPEAT, TileMode.CLAMP);
mPaint.setShader(mShader);
}
}
Aggregations