use of android.graphics.BitmapShader in project CircularImageView by Pkmmte.
the class RoundTransform method transform.
@Override
public Bitmap transform(final Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
if (source != output) {
source.recycle();
}
return output;
}
use of android.graphics.BitmapShader in project HoloEverywhere by Prototik.
the class ProgressBar method tileify.
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 if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
for (int i = 0; i < numStates; i++) {
out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
}
return out;
} else 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 Rajawali by Rajawali.
the class GitHubLogoView method onSizeChanged.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mDrawingRect = new Rect(0, 0, w, h);
final Bitmap mask = convertToAlphaMask(Bitmap.createScaledBitmap(mMask, w, h, false));
mPaint.setShader(new BitmapShader(mask, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
mBackground = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mBackgroundCanvas.setBitmap(mBackground);
}
use of android.graphics.BitmapShader in project ProgressWheel by Todd-Davies.
the class Main method randomBg.
private static void randomBg(ProgressWheel wheel) {
Random random = new Random();
int firstColour = random.nextInt();
int secondColour = random.nextInt();
int patternSize = (1 + random.nextInt(3)) * 8;
int patternChange = (1 + random.nextInt(3)) * 8;
int[] pixels = new int[patternSize];
for (int i = 0; i < patternSize; i++) {
pixels[i] = (i > patternChange) ? firstColour : secondColour;
}
wheel.setRimShader(new BitmapShader(Bitmap.createBitmap(pixels, patternSize, 1, Bitmap.Config.ARGB_8888), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
}
use of android.graphics.BitmapShader in project Carbon by ZieIony.
the class CheckableDrawable method renderSVGs.
private void renderSVGs() {
Rect bounds = getBounds();
if (bounds.width() <= 0 && bounds.height() <= 0)
return;
try {
{
SVG svg = SVG.getFromResource(context, checkedRes);
checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(checkedBitmap);
svg.setDocumentWidth(checkedBitmap.getWidth());
svg.setDocumentHeight(checkedBitmap.getHeight());
svg.renderToCanvas(canvas);
checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.postTranslate(bounds.left, bounds.top);
checkedShader.setLocalMatrix(matrix);
}
{
SVG svg2 = SVG.getFromResource(context, uncheckedRes);
uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(uncheckedBitmap);
svg2.setDocumentWidth(uncheckedBitmap.getWidth());
svg2.setDocumentHeight(uncheckedBitmap.getHeight());
svg2.renderToCanvas(canvas);
}
{
SVG svg3 = SVG.getFromResource(context, filledRes);
filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(filledBitmap);
svg3.setDocumentWidth(filledBitmap.getWidth());
svg3.setDocumentHeight(filledBitmap.getHeight());
svg3.renderToCanvas(canvas);
}
maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
maskCanvas = new Canvas(maskBitmap);
radius = (float) (Math.sqrt(2) * bounds.width() / 2);
} catch (SVGParseException e) {
Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
} catch (NullPointerException e) {
// TODO: what is this catch for?
}
}
Aggregations